Bluesky app fork with some witchin' additions 馃挮
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

at 8c3553cd66ad07ef8c8c4e760b495cf6ce08cc8d 102 lines 3.0 kB view raw
1import React from 'react' 2import {View} from 'react-native' 3import {msg, Trans} from '@lingui/macro' 4import {useLingui} from '@lingui/react' 5 6import {logEvent} from '#/lib/statsig/statsig' 7import {logger} from '#/logger' 8import {type SessionAccount, useSession, useSessionApi} from '#/state/session' 9import {useLoggedOutViewControls} from '#/state/shell/logged-out' 10import * as Toast from '#/view/com/util/Toast' 11import {atoms as a, web} from '#/alf' 12import {AccountList} from '#/components/AccountList' 13import {Button, ButtonText} from '#/components/Button' 14import * as TextField from '#/components/forms/TextField' 15import {FormContainer} from './FormContainer' 16 17export const ChooseAccountForm = ({ 18 onSelectAccount, 19 onPressBack, 20}: { 21 onSelectAccount: (account?: SessionAccount) => void 22 onPressBack: () => void 23}) => { 24 const [pendingDid, setPendingDid] = React.useState<string | null>(null) 25 const {_} = useLingui() 26 const {currentAccount} = useSession() 27 const {resumeSession} = useSessionApi() 28 const {setShowLoggedOut} = useLoggedOutViewControls() 29 30 const onSelect = React.useCallback( 31 async (account: SessionAccount) => { 32 if (pendingDid) { 33 // The session API isn't resilient to race conditions so let's just ignore this. 34 return 35 } 36 if (!account.accessJwt) { 37 // Move to login form. 38 onSelectAccount(account) 39 return 40 } 41 if (account.did === currentAccount?.did) { 42 setShowLoggedOut(false) 43 Toast.show(_(msg`Already signed in as @${account.handle}`)) 44 return 45 } 46 try { 47 setPendingDid(account.did) 48 await resumeSession(account, true) 49 logEvent('account:loggedIn', { 50 logContext: 'ChooseAccountForm', 51 withPassword: false, 52 }) 53 Toast.show(_(msg`Signed in as @${account.handle}`)) 54 } catch (e: any) { 55 logger.error('choose account: initSession failed', { 56 message: e.message, 57 }) 58 // Move to login form. 59 onSelectAccount(account) 60 } finally { 61 setPendingDid(null) 62 } 63 }, 64 [ 65 currentAccount, 66 resumeSession, 67 pendingDid, 68 onSelectAccount, 69 setShowLoggedOut, 70 _, 71 ], 72 ) 73 74 return ( 75 <FormContainer 76 testID="chooseAccountForm" 77 titleText={<Trans>Select account</Trans>} 78 style={web([a.py_2xl])}> 79 <View> 80 <TextField.LabelText> 81 <Trans>Sign in as...</Trans> 82 </TextField.LabelText> 83 <AccountList 84 onSelectAccount={onSelect} 85 onSelectOther={() => onSelectAccount()} 86 pendingDid={pendingDid} 87 /> 88 </View> 89 <View style={[a.flex_row]}> 90 <Button 91 label={_(msg`Back`)} 92 variant="solid" 93 color="secondary" 94 size="large" 95 onPress={onPressBack}> 96 <ButtonText>{_(msg`Back`)}</ButtonText> 97 </Button> 98 <View style={[a.flex_1]} /> 99 </View> 100 </FormContainer> 101 ) 102}