import {Fragment, useCallback} from 'react' import {View} from 'react-native' import {type AppBskyActorDefs} from '@atproto/api' import {msg} from '@lingui/core/macro' import {useLingui} from '@lingui/react' import {Trans} from '@lingui/react/macro' import {isJwtExpired} from '#/lib/jwt' import {sanitizeDisplayName} from '#/lib/strings/display-names' import {sanitizeHandle} from '#/lib/strings/handles' import {useEnableSquareButtons} from '#/state/preferences/enable-square-buttons' import {useProfilesQuery} from '#/state/queries/profile' import {type SessionAccount, useSession} from '#/state/session' import {useSortedAccountItems} from '#/state/session/sorting' import {UserAvatar} from '#/view/com/util/UserAvatar' import {atoms as a, useTheme} from '#/alf' import {Button} from '#/components/Button' 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 {ProfileBadges} from '#/components/ProfileBadges' import {Text} from '#/components/Typography' import {useActorStatus} from '#/features/liveNow' import {useHiddenAccountsElsewhere} from '#/storage/hooks/hidden-accounts-elsewhere' export function AccountList({ onSelectAccount, onSelectOther, otherLabel, pendingDid, }: { onSelectAccount: (account: SessionAccount) => void onSelectOther: () => void otherLabel?: string pendingDid: string | null }) { const {currentAccount, accounts} = useSession() const t = useTheme() const {_} = useLingui() const enableSquareButtons = useEnableSquareButtons() const [, , hiddenDidsSet] = useHiddenAccountsElsewhere() const {data: profiles} = useProfilesQuery({ handles: accounts.map(acc => acc.did), }) const sortedAccounts = useSortedAccountItems(accounts).filter( account => !hiddenDidsSet.has(account.did), ) const onPressAddAccount = useCallback(() => { onSelectOther() }, [onSelectOther]) return ( {sortedAccounts.map(account => ( p.did === account.did)} account={account} onSelect={onSelectAccount} isCurrentAccount={account.did === currentAccount?.did} isPendingAccount={account.did === pendingDid} /> ))} ) } function AccountItem({ profile, account, onSelect, isCurrentAccount, isPendingAccount, }: { profile?: AppBskyActorDefs.ProfileViewDetailed account: SessionAccount onSelect: (account: SessionAccount) => void isCurrentAccount: boolean isPendingAccount: boolean }) { const t = useTheme() const {_} = useLingui() const {isActive: live} = useActorStatus(profile) const enableSquareButtons = useEnableSquareButtons() const onPress = useCallback(() => { onSelect(account) }, [account, onSelect]) const isLoggedOut = account.isOauthSession ? false // OAuth sessions are managed by the OAuth client, not refreshJwt : !account.refreshJwt || isJwtExpired(account.refreshJwt) return ( ) }