import React from 'react' import { ActivityIndicator, ScrollView, TouchableOpacity, View, } from 'react-native' import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome' import {useAnalytics} from 'lib/analytics/analytics' import {Text} from '../../util/text/Text' import {UserAvatar} from '../../util/UserAvatar' import {s} from 'lib/styles' import {RootStoreModel} from 'state/index' import {AccountData} from 'state/models/session' import {usePalette} from 'lib/hooks/usePalette' import {Trans, msg} from '@lingui/macro' import {useLingui} from '@lingui/react' import {styles} from './styles' export const ChooseAccountForm = ({ store, onSelectAccount, onPressBack, }: { store: RootStoreModel onSelectAccount: (account?: AccountData) => void onPressBack: () => void }) => { const {track, screen} = useAnalytics() const pal = usePalette('default') const [isProcessing, setIsProcessing] = React.useState(false) const {_} = useLingui() React.useEffect(() => { screen('Choose Account') }, [screen]) const onTryAccount = async (account: AccountData) => { if (account.accessJwt && account.refreshJwt) { setIsProcessing(true) if (await store.session.resumeSession(account)) { track('Sign In', {resumedSession: true}) setIsProcessing(false) return } setIsProcessing(false) } onSelectAccount(account) } return ( Sign in as... {store.session.accounts.map(account => ( onTryAccount(account)} accessibilityRole="button" accessibilityLabel={_(msg`Sign in as ${account.handle}`)} accessibilityHint="Double tap to sign in"> {account.displayName || account.handle}{' '} {account.handle} ))} onSelectAccount(undefined)} accessibilityRole="button" accessibilityLabel={_(msg`Login to account that is not listed`)} accessibilityHint=""> Other account Back {isProcessing && } ) }