mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
0
fork

Configure Feed

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

at switch-session-failure 146 lines 4.2 kB view raw
1import React, {useCallback} from 'react' 2import {View} from 'react-native' 3import {msg, Trans} from '@lingui/macro' 4import {useLingui} from '@lingui/react' 5 6import {useProfileQuery} from '#/state/queries/profile' 7import {type SessionAccount, useSession} from '#/state/session' 8import {UserAvatar} from '#/view/com/util/UserAvatar' 9import {atoms as a, useTheme} from '#/alf' 10import {Check_Stroke2_Corner0_Rounded as Check} from '#/components/icons/Check' 11import {ChevronRight_Stroke2_Corner0_Rounded as Chevron} from '#/components/icons/Chevron' 12import {Button} from './Button' 13import {Text} from './Typography' 14 15export function AccountList({ 16 onSelectAccount, 17 onSelectOther, 18 otherLabel, 19 pendingDid, 20}: { 21 onSelectAccount: (account: SessionAccount) => void 22 onSelectOther: () => void 23 otherLabel?: string 24 pendingDid: string | null 25}) { 26 const {currentAccount, accounts} = useSession() 27 const t = useTheme() 28 const {_} = useLingui() 29 30 const onPressAddAccount = useCallback(() => { 31 onSelectOther() 32 }, [onSelectOther]) 33 34 return ( 35 <View 36 pointerEvents={pendingDid ? 'none' : 'auto'} 37 style={[ 38 a.rounded_md, 39 a.overflow_hidden, 40 a.border, 41 t.atoms.border_contrast_low, 42 ]}> 43 {accounts.map(account => ( 44 <React.Fragment key={account.did}> 45 <AccountItem 46 account={account} 47 onSelect={onSelectAccount} 48 isCurrentAccount={account.did === currentAccount?.did} 49 isPendingAccount={account.did === pendingDid} 50 /> 51 <View style={[a.border_b, t.atoms.border_contrast_low]} /> 52 </React.Fragment> 53 ))} 54 <Button 55 testID="chooseAddAccountBtn" 56 style={[a.flex_1]} 57 onPress={pendingDid ? undefined : onPressAddAccount} 58 label={_(msg`Login to account that is not listed`)}> 59 {({hovered, pressed}) => ( 60 <View 61 style={[ 62 a.flex_1, 63 a.flex_row, 64 a.align_center, 65 {height: 48}, 66 (hovered || pressed) && t.atoms.bg_contrast_25, 67 ]}> 68 <Text 69 style={[ 70 a.align_baseline, 71 a.flex_1, 72 a.flex_row, 73 a.py_sm, 74 {paddingLeft: 48}, 75 ]}> 76 {otherLabel ?? <Trans>Other account</Trans>} 77 </Text> 78 <Chevron size="sm" style={[t.atoms.text, a.mr_md]} /> 79 </View> 80 )} 81 </Button> 82 </View> 83 ) 84} 85 86function AccountItem({ 87 account, 88 onSelect, 89 isCurrentAccount, 90 isPendingAccount, 91}: { 92 account: SessionAccount 93 onSelect: (account: SessionAccount) => void 94 isCurrentAccount: boolean 95 isPendingAccount: boolean 96}) { 97 const t = useTheme() 98 const {_} = useLingui() 99 const {data: profile} = useProfileQuery({did: account.did}) 100 101 const onPress = React.useCallback(() => { 102 onSelect(account) 103 }, [account, onSelect]) 104 105 return ( 106 <Button 107 testID={`chooseAccountBtn-${account.handle}`} 108 key={account.did} 109 style={[a.flex_1]} 110 onPress={onPress} 111 label={ 112 isCurrentAccount 113 ? _(msg`Continue as ${account.handle} (currently signed in)`) 114 : _(msg`Sign in as ${account.handle}`) 115 }> 116 {({hovered, pressed}) => ( 117 <View 118 style={[ 119 a.flex_1, 120 a.flex_row, 121 a.align_center, 122 {height: 48}, 123 (hovered || pressed || isPendingAccount) && t.atoms.bg_contrast_25, 124 ]}> 125 <View style={a.p_md}> 126 <UserAvatar avatar={profile?.avatar} size={24} /> 127 </View> 128 <Text style={[a.align_baseline, a.flex_1, a.flex_row, a.py_sm]}> 129 <Text style={[a.font_bold]}> 130 {profile?.displayName || account.handle}{' '} 131 </Text> 132 <Text style={[t.atoms.text_contrast_medium]}>{account.handle}</Text> 133 </Text> 134 {isCurrentAccount ? ( 135 <Check 136 size="sm" 137 style={[{color: t.palette.positive_600}, a.mr_md]} 138 /> 139 ) : ( 140 <Chevron size="sm" style={[t.atoms.text, a.mr_md]} /> 141 )} 142 </View> 143 )} 144 </Button> 145 ) 146}