Select account redesign (#8905)

* new designs for select account

* tweak web styles

* add logged out indicator

* unify helper function

* move error, try catch
This commit is contained in:
Samuel Newman
2025-11-10 16:02:53 +02:00
committed by GitHub
parent 4791486aa7
commit ad91029f10
5 changed files with 90 additions and 39 deletions
+58 -24
View File
@@ -5,18 +5,20 @@ import {msg, Trans} from '@lingui/macro'
import {useLingui} from '@lingui/react' import {useLingui} from '@lingui/react'
import {useActorStatus} from '#/lib/actor-status' import {useActorStatus} from '#/lib/actor-status'
import {isJwtExpired} from '#/lib/jwt'
import {sanitizeDisplayName} from '#/lib/strings/display-names' import {sanitizeDisplayName} from '#/lib/strings/display-names'
import {sanitizeHandle} from '#/lib/strings/handles' import {sanitizeHandle} from '#/lib/strings/handles'
import {useProfilesQuery} from '#/state/queries/profile' import {useProfilesQuery} from '#/state/queries/profile'
import {type SessionAccount, useSession} from '#/state/session' import {type SessionAccount, useSession} from '#/state/session'
import {UserAvatar} from '#/view/com/util/UserAvatar' import {UserAvatar} from '#/view/com/util/UserAvatar'
import {atoms as a, useTheme} from '#/alf' import {atoms as a, useTheme} from '#/alf'
import {Check_Stroke2_Corner0_Rounded as Check} from '#/components/icons/Check' import {Button} from '#/components/Button'
import {ChevronRight_Stroke2_Corner0_Rounded as Chevron} from '#/components/icons/Chevron' import {CheckThick_Stroke2_Corner0_Rounded as CheckIcon} from '#/components/icons/Check'
import {ChevronRight_Stroke2_Corner0_Rounded as ChevronIcon} from '#/components/icons/Chevron'
import {PlusLarge_Stroke2_Corner0_Rounded as PlusIcon} from '#/components/icons/Plus'
import {Text} from '#/components/Typography'
import {useSimpleVerificationState} from '#/components/verification' import {useSimpleVerificationState} from '#/components/verification'
import {VerificationCheck} from '#/components/verification/VerificationCheck' import {VerificationCheck} from '#/components/verification/VerificationCheck'
import {Button} from './Button'
import {Text} from './Typography'
export function AccountList({ export function AccountList({
onSelectAccount, onSelectAccount,
@@ -44,9 +46,9 @@ export function AccountList({
<View <View
pointerEvents={pendingDid ? 'none' : 'auto'} pointerEvents={pendingDid ? 'none' : 'auto'}
style={[ style={[
a.rounded_md, a.rounded_lg,
a.overflow_hidden, a.overflow_hidden,
{borderWidth: 1}, a.border,
t.atoms.border_contrast_low, t.atoms.border_contrast_low,
]}> ]}>
{accounts.map(account => ( {accounts.map(account => (
@@ -58,7 +60,7 @@ export function AccountList({
isCurrentAccount={account.did === currentAccount?.did} isCurrentAccount={account.did === currentAccount?.did}
isPendingAccount={account.did === pendingDid} isPendingAccount={account.did === pendingDid}
/> />
<View style={[{borderBottomWidth: 1}, t.atoms.border_contrast_low]} /> <View style={[a.border_b, t.atoms.border_contrast_low]} />
</React.Fragment> </React.Fragment>
))} ))}
<Button <Button
@@ -72,22 +74,25 @@ export function AccountList({
a.flex_1, a.flex_1,
a.flex_row, a.flex_row,
a.align_center, a.align_center,
{height: 48}, a.p_lg,
a.gap_sm,
(hovered || pressed) && t.atoms.bg_contrast_25, (hovered || pressed) && t.atoms.bg_contrast_25,
]}> ]}>
<Text <View
style={[ style={[
a.font_semi_bold, t.atoms.bg_contrast_25,
a.flex_1, a.rounded_full,
a.flex_row, {width: 48, height: 48},
a.py_sm, a.justify_center,
a.leading_tight, a.align_center,
t.atoms.text_contrast_medium, (hovered || pressed) && t.atoms.bg_contrast_50,
{paddingLeft: 56},
]}> ]}>
<PlusIcon style={[t.atoms.text_contrast_low]} size="md" />
</View>
<Text style={[a.flex_1, a.leading_tight, a.text_md, a.font_medium]}>
{otherLabel ?? <Trans>Other account</Trans>} {otherLabel ?? <Trans>Other account</Trans>}
</Text> </Text>
<Chevron size="sm" style={[t.atoms.text, a.mr_md]} /> <ChevronIcon size="md" style={[t.atoms.text_contrast_low]} />
</View> </View>
)} )}
</Button> </Button>
@@ -117,6 +122,8 @@ function AccountItem({
onSelect(account) onSelect(account)
}, [account, onSelect]) }, [account, onSelect])
const isLoggedOut = !account.refreshJwt || isJwtExpired(account.refreshJwt)
return ( return (
<Button <Button
testID={`chooseAccountBtn-${account.handle}`} testID={`chooseAccountBtn-${account.handle}`}
@@ -134,14 +141,13 @@ function AccountItem({
a.flex_1, a.flex_1,
a.flex_row, a.flex_row,
a.align_center, a.align_center,
a.px_md, a.p_lg,
a.gap_sm, a.gap_sm,
{height: 56},
(hovered || pressed || isPendingAccount) && t.atoms.bg_contrast_25, (hovered || pressed || isPendingAccount) && t.atoms.bg_contrast_25,
]}> ]}>
<UserAvatar <UserAvatar
avatar={profile?.avatar} avatar={profile?.avatar}
size={36} size={48}
type={profile?.associated?.labeler ? 'labeler' : 'user'} type={profile?.associated?.labeler ? 'labeler' : 'user'}
live={live} live={live}
hideLiveBadge hideLiveBadge
@@ -151,7 +157,7 @@ function AccountItem({
<View style={[a.flex_row, a.align_center, a.gap_xs]}> <View style={[a.flex_row, a.align_center, a.gap_xs]}>
<Text <Text
emoji emoji
style={[a.font_semi_bold, a.leading_tight]} style={[a.font_medium, a.leading_tight, a.text_md]}
numberOfLines={1}> numberOfLines={1}>
{sanitizeDisplayName( {sanitizeDisplayName(
profile?.displayName || profile?.handle || account.handle, profile?.displayName || profile?.handle || account.handle,
@@ -166,15 +172,43 @@ function AccountItem({
</View> </View>
)} )}
</View> </View>
<Text style={[a.leading_tight, t.atoms.text_contrast_medium]}> <Text
style={[
a.leading_tight,
t.atoms.text_contrast_medium,
a.text_sm,
]}>
{sanitizeHandle(account.handle, '@')} {sanitizeHandle(account.handle, '@')}
</Text> </Text>
{isLoggedOut && (
<Text
style={[
a.leading_tight,
a.text_xs,
a.italic,
t.atoms.text_contrast_medium,
]}>
<Trans>Logged out</Trans>
</Text>
)}
</View> </View>
{isCurrentAccount ? ( {isCurrentAccount ? (
<Check size="sm" style={[{color: t.palette.positive_500}]} /> <View
style={[
{
width: 20,
height: 20,
backgroundColor: t.palette.positive_500,
},
a.rounded_full,
a.justify_center,
a.align_center,
]}>
<CheckIcon size="xs" style={[{color: t.palette.white}]} />
</View>
) : ( ) : (
<Chevron size="sm" style={[t.atoms.text]} /> <ChevronIcon size="md" style={[t.atoms.text_contrast_low]} />
)} )}
</View> </View>
)} )}
+1 -1
View File
@@ -41,7 +41,7 @@ export function SwitchAccountDialog({
}, [setShowLoggedOut, control]) }, [setShowLoggedOut, control])
return ( return (
<Dialog.Outer control={control}> <Dialog.Outer control={control} nativeOptions={{preventExpansion: true}}>
<Dialog.Handle /> <Dialog.Handle />
<Dialog.ScrollableInner label={_(msg`Switch Account`)}> <Dialog.ScrollableInner label={_(msg`Switch Account`)}>
<View style={[a.gap_lg]}> <View style={[a.gap_lg]}>
+23
View File
@@ -0,0 +1,23 @@
import {jwtDecode} from 'jwt-decode'
import {logger} from '#/logger'
/**
* Simple check if a JWT token has expired. Does *not* validate the token or check for revocation status,
* just checks the expiration time.
*
* @param token The JWT token to check.
* @returns `true` if the token has expired, `false` otherwise.
*/
export function isJwtExpired(token: string) {
try {
const payload = jwtDecode(token)
if (!payload.exp) return true
const now = Math.floor(Date.now() / 1000)
return now >= payload.exp
} catch {
logger.error(`session: could not decode jwt`)
return true // invalid token or parse error
}
}
+3 -2
View File
@@ -8,7 +8,7 @@ import {logger} from '#/logger'
import {type SessionAccount, useSession, useSessionApi} from '#/state/session' import {type SessionAccount, useSession, useSessionApi} from '#/state/session'
import {useLoggedOutViewControls} from '#/state/shell/logged-out' import {useLoggedOutViewControls} from '#/state/shell/logged-out'
import * as Toast from '#/view/com/util/Toast' import * as Toast from '#/view/com/util/Toast'
import {atoms as a} from '#/alf' import {atoms as a, web} from '#/alf'
import {AccountList} from '#/components/AccountList' import {AccountList} from '#/components/AccountList'
import {Button, ButtonText} from '#/components/Button' import {Button, ButtonText} from '#/components/Button'
import * as TextField from '#/components/forms/TextField' import * as TextField from '#/components/forms/TextField'
@@ -74,7 +74,8 @@ export const ChooseAccountForm = ({
return ( return (
<FormContainer <FormContainer
testID="chooseAccountForm" testID="chooseAccountForm"
titleText={<Trans>Select account</Trans>}> titleText={<Trans>Select account</Trans>}
style={web([a.py_2xl])}>
<View> <View>
<TextField.LabelText> <TextField.LabelText>
<Trans>Sign in as...</Trans> <Trans>Sign in as...</Trans>
+5 -12
View File
@@ -1,7 +1,7 @@
import {jwtDecode} from 'jwt-decode' import {jwtDecode} from 'jwt-decode'
import {isJwtExpired} from '#/lib/jwt'
import {hasProp} from '#/lib/type-guards' import {hasProp} from '#/lib/type-guards'
import {logger} from '#/logger'
import * as persisted from '#/state/persisted' import * as persisted from '#/state/persisted'
import {type SessionAccount} from './types' import {type SessionAccount} from './types'
@@ -22,16 +22,9 @@ export function isSignupQueued(accessJwt: string | undefined) {
} }
export function isSessionExpired(account: SessionAccount) { export function isSessionExpired(account: SessionAccount) {
try { if (account.accessJwt) {
if (account.accessJwt) { return isJwtExpired(account.accessJwt)
const decoded = jwtDecode(account.accessJwt) } else {
if (decoded.exp) { return true
const didExpire = Date.now() >= decoded.exp * 1000
return didExpire
}
}
} catch (e) {
logger.error(`session: could not decode jwt`)
} }
return true
} }