import React, {useCallback} from 'react' import {View} from 'react-native' import {type AppBskyActorDefs} from '@atproto/api' import {msg, Trans} from '@lingui/macro' import {useLingui} from '@lingui/react' import {useActorStatus} from '#/lib/actor-status' 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 {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 {Text} from '#/components/Typography' import {useSimpleVerificationState} from '#/components/verification' import {VerificationCheck} from '#/components/verification/VerificationCheck' 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 {data: profiles} = useProfilesQuery({ handles: accounts.map(acc => acc.did), }) const onPressAddAccount = useCallback(() => { onSelectOther() }, [onSelectOther]) return ( {accounts.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 verification = useSimpleVerificationState({profile}) const {isActive: live} = useActorStatus(profile) const enableSquareButtons = useEnableSquareButtons() const onPress = useCallback(() => { onSelect(account) }, [account, onSelect]) const isLoggedOut = !account.refreshJwt || isJwtExpired(account.refreshJwt) return ( ) }