mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
at samuel/exp-cli 64 lines 1.9 kB view raw
1import {useCallback} from 'react' 2import {View} from 'react-native' 3import {msg, Trans} from '@lingui/macro' 4import {useLingui} from '@lingui/react' 5 6import {useAccountSwitcher} from '#/lib/hooks/useAccountSwitcher' 7import {type SessionAccount, useSession} from '#/state/session' 8import {useLoggedOutViewControls} from '#/state/shell/logged-out' 9import {atoms as a} from '#/alf' 10import * as Dialog from '#/components/Dialog' 11import {AccountList} from '../AccountList' 12import {Text} from '../Typography' 13 14export function SwitchAccountDialog({ 15 control, 16}: { 17 control: Dialog.DialogControlProps 18}) { 19 const {_} = useLingui() 20 const {currentAccount} = useSession() 21 const {onPressSwitchAccount, pendingDid} = useAccountSwitcher() 22 const {setShowLoggedOut} = useLoggedOutViewControls() 23 24 const onSelectAccount = useCallback( 25 (account: SessionAccount) => { 26 if (account.did !== currentAccount?.did) { 27 control.close(() => { 28 onPressSwitchAccount(account, 'SwitchAccount') 29 }) 30 } else { 31 control.close() 32 } 33 }, 34 [currentAccount, control, onPressSwitchAccount], 35 ) 36 37 const onPressAddAccount = useCallback(() => { 38 control.close(() => { 39 setShowLoggedOut(true) 40 }) 41 }, [setShowLoggedOut, control]) 42 43 return ( 44 <Dialog.Outer control={control}> 45 <Dialog.Handle /> 46 <Dialog.ScrollableInner label={_(msg`Switch Account`)}> 47 <View style={[a.gap_lg]}> 48 <Text style={[a.text_2xl, a.font_bold]}> 49 <Trans>Switch Account</Trans> 50 </Text> 51 52 <AccountList 53 onSelectAccount={onSelectAccount} 54 onSelectOther={onPressAddAccount} 55 otherLabel={_(msg`Add account`)} 56 pendingDid={pendingDid} 57 /> 58 </View> 59 60 <Dialog.Close /> 61 </Dialog.ScrollableInner> 62 </Dialog.Outer> 63 ) 64}