Skip to content

Commit 4cc8833

Browse files
authored
indicate which provider last successfully signed in (#11274)
1 parent e30224a commit 4cc8833

4 files changed

Lines changed: 40 additions & 4 deletions

File tree

react-common/components/profile/SignInModal.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@ export interface SignInModalProps {
1717
}
1818
resolvePath?: (path: string) => string
1919
mode?: "signin" | "signup"
20+
lastUsedIdentityProvider?: pxt.IdentityProviderId
2021
}
2122

2223
export const SignInModal = (props: SignInModalProps) => {
23-
const { onSignIn, onClose, appMessage, dialogMessages, hideDismissButton } = props
24+
const { onSignIn, onClose, appMessage, dialogMessages, hideDismissButton, lastUsedIdentityProvider } = props
2425
const { signInMessage, signUpMessage } = dialogMessages || {
2526
signInMessage: lf("Sign in to save your progress and access your work anytime, anywhere."),
2627
signUpMessage: lf("Join now to save your progress and access your work anytime, anywhere.")
@@ -70,19 +71,24 @@ export const SignInModal = (props: SignInModalProps) => {
7071
<div className='signin-body'>
7172
<div className='providers'>
7273
{pxt.auth.identityProviders().map((provider, index) => {
74+
const isLastUsedProvider = provider.id === lastUsedIdentityProvider
7375
const title =
7476
mode === "signin"
7577
? lf("Continue with {0}", provider.name)
7678
: lf("Sign up with {0}", provider.name)
79+
const ariaLabel = isLastUsedProvider
80+
? lf("{0}. You last used this option.", title)
81+
: title
7782
return (
7883
<Button
7984
key={index}
8085
className='provider'
8186
onClick={() => onSignIn(provider, rememberMe)}
8287
title={title}
83-
ariaLabel={title}
88+
ariaLabel={ariaLabel}
8489
label={
8590
<div className='label'>
91+
{isLastUsedProvider && <div className='ui orange right ribbon label last-used-ribbon' aria-hidden="true">{lf("Last used")}</div>}
8692
<div>
8793
<img className='logo' src={resolvePath(provider.icon)} />
8894
</div>

react-common/styles/profile/profile.less

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,18 +400,31 @@
400400
background-color: var(--pxt-neutral-background1);
401401
color: var(--pxt-neutral-foreground1);
402402
border: solid 1px var(--pxt-neutral-foreground1);
403+
position: relative;
404+
overflow: visible;
403405

404406
.label {
405407
display: flex;
406408
flex-direction: row;
407409
gap: 1rem;
410+
align-items: center;
411+
412+
.last-used-ribbon {
413+
position: absolute;
414+
top: -1rem;
415+
right: -1rem;
416+
left: auto;
417+
transform: none;
418+
margin-right: 0;
419+
z-index: 1;
420+
}
408421

409422
.logo {
410423
width: 1.25rem;
411424
}
412425

413426
.title {
414-
align-self: center;
427+
text-align: left;
415428
}
416429
}
417430
}

webapp/src/auth.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export const COLOR_THEME_IDS = `${USER_PREF_MODULE}:${FIELD_COLOR_THEME_IDS}`
2626
export const LANGUAGE = `${USER_PREF_MODULE}:${FIELD_LANGUAGE}`
2727
export const READER = `${USER_PREF_MODULE}:${FIELD_READER}`
2828
export const HAS_USED_CLOUD = "has-used-cloud"; // Key into local storage to see if this computer has logged in before
29+
export const LAST_IDENTITY_PROVIDER = "last-identity-provider";
2930

3031
export class Component<TProps, TState> extends data.Component<TProps, TState> {
3132
public getUserProfile(): pxt.auth.UserProfile {
@@ -46,6 +47,11 @@ class AuthClient extends pxt.auth.AuthClient {
4647
if (!!workspace.getWorkspaceType())
4748
await cloud.syncAsync();
4849
pxt.storage.setLocal(HAS_USED_CLOUD, "true");
50+
51+
const providerId = pxt.auth.identityProviderId(state.profile);
52+
if (providerId) {
53+
pxt.storage.setLocal(LAST_IDENTITY_PROVIDER, providerId);
54+
}
4955
}
5056
protected onSignedOut(): Promise<void> {
5157
core.infoNotification(lf("Signed out"));
@@ -195,6 +201,11 @@ export function userPreferences(): pxt.auth.UserPreferences {
195201
return data.getData<pxt.auth.UserPreferences>(USER_PREFERENCES);
196202
}
197203

204+
export function lastUsedIdentityProviderId(): pxt.IdentityProviderId | undefined {
205+
const providerId = pxt.storage.getLocal(LAST_IDENTITY_PROVIDER) as pxt.IdentityProviderId;
206+
return pxt.auth.identityProvider(providerId) ? providerId : undefined;
207+
}
208+
198209
export async function authCheckAsync(): Promise<pxt.auth.UserProfile | undefined> {
199210
const cli = await clientAsync();
200211
return await cli?.authCheckAsync();

webapp/src/identity.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,15 @@ export class LoginDialog extends auth.Component<LoginDialogProps, LoginDialogSta
5353

5454
renderCore() {
5555
const { visible, dialogMessages } = this.state;
56+
const lastUsedIdentityProvider = auth.lastUsedIdentityProviderId();
5657

5758
return <>
58-
{visible && <SignInModal onClose={this.hide} onSignIn={this.signInAsync} dialogMessages={dialogMessages} />}
59+
{visible && <SignInModal
60+
onClose={this.hide}
61+
onSignIn={this.signInAsync}
62+
dialogMessages={dialogMessages}
63+
lastUsedIdentityProvider={lastUsedIdentityProvider}
64+
/>}
5965
</>;
6066
}
6167
}

0 commit comments

Comments
 (0)