deer social fork for personal usage. but you might see a use idk. github mirror
4
fork

Configure Feed

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

Merge branch 'accountswitcher'

ayla 40ba9d45 d5059e51

+69 -32
+56 -19
src/view/com/composer/Composer.tsx
··· 99 99 import {usePreferencesQuery} from '#/state/queries/preferences' 100 100 import {useProfilesQuery} from '#/state/queries/profile' 101 101 import {type Gif} from '#/state/queries/tenor' 102 - import {type SessionAccount, useAgent, useSession} from '#/state/session' 102 + import {useAgent, useSession} from '#/state/session' 103 103 import {useComposerControls} from '#/state/shell/composer' 104 104 import {type ComposerOpts, type OnPostSuccessData} from '#/state/shell/composer' 105 105 import {useLoggedOutViewControls} from '#/state/shell/logged-out' ··· 182 182 }) => { 183 183 const {currentAccount, accounts} = useSession() 184 184 const defaultAgent = useAgent() 185 - const [selectedAccount, setSelectedAccount] = useState(currentAccount!) 185 + const [selectedAccountDid, setSelectedAccountDid] = useState( 186 + currentAccount!.did, 187 + ) 186 188 187 189 const {data: agent = defaultAgent} = useQuery({ 188 190 queryKey: [ ··· 190 192 currentAccount?.did, 191 193 currentAccount?.service, 192 194 currentAccount?.active, 193 - selectedAccount?.did, 194 - selectedAccount?.service, 195 - selectedAccount?.accessJwt, 196 - selectedAccount?.refreshJwt, 197 - selectedAccount?.active, 195 + selectedAccountDid, 196 + // include account data in the query key to invalidate when tokens change 197 + // hmm we don't want a nested array i think so spreading seems like the way to go(?) 198 + ...(() => { 199 + const selectedAccount = accounts.find( 200 + acc => acc.did === selectedAccountDid, 201 + ) 202 + return selectedAccount 203 + ? [ 204 + selectedAccount.service, 205 + selectedAccount.accessJwt, 206 + selectedAccount.refreshJwt, 207 + selectedAccount.active, 208 + ] 209 + : [] 210 + })(), 198 211 ], 199 212 queryFn: async () => { 200 - if (selectedAccount.did === currentAccount!.did) { 213 + if (selectedAccountDid === currentAccount!.did) { 201 214 return defaultAgent 202 215 } 216 + 217 + // get fresh account data from the session store 218 + const selectedAccount = accounts.find( 219 + acc => acc.did === selectedAccountDid, 220 + ) 221 + if (!selectedAccount) { 222 + throw new Error(`Account with DID ${selectedAccountDid} not found`) 223 + } 224 + 203 225 const session = new CredentialSession(new URL(selectedAccount.service)) 204 226 if ( 205 227 selectedAccount.refreshJwt && ··· 219 241 }) 220 242 221 243 const queryClient = useQueryClient() 222 - const currentDid = selectedAccount.did 244 + const currentDid = selectedAccountDid 223 245 const {closeComposer} = useComposerControls() 224 246 const {requestSwitchToAccount} = useLoggedOutViewControls() 225 247 const {_} = useLingui() ··· 236 258 handles: accounts.map(acc => acc.did), 237 259 }) 238 260 261 + // if accounts array changes, invalidate agent so we still have fresh tokens 262 + useEffect(() => { 263 + queryClient.invalidateQueries({ 264 + queryKey: ['composer-agent'], 265 + }) 266 + }, [accounts, queryClient]) 267 + 239 268 const [isKeyboardVisible] = useIsKeyboardVisible({iosUseWillEvents: true}) 240 269 const [isPublishing, setIsPublishing] = useState(false) 241 270 const [publishingStage, setPublishingStage] = useState('') ··· 254 283 ) 255 284 256 285 const onSelectAccount = React.useCallback( 257 - async (account: SessionAccount) => { 258 - if (account.did === selectedAccount.did) { 286 + async (accountDid: string) => { 287 + if (accountDid === selectedAccountDid) { 288 + return 289 + } 290 + 291 + // get fresh account data from session store 292 + const account = accounts.find(acc => acc.did === accountDid) 293 + if (!account) { 294 + setError('Account not found') 259 295 return 260 296 } 261 297 ··· 281 317 currentAccount?.did, 282 318 currentAccount?.service, 283 319 currentAccount?.active, 284 - account.did, 320 + accountDid, 285 321 account.service, 286 322 account.accessJwt, 287 323 account.refreshJwt, ··· 290 326 tempAgent, 291 327 ) 292 328 // if it succeeds, update the selected account 293 - setSelectedAccount(account) 329 + setSelectedAccountDid(accountDid) 294 330 } catch (e: any) { 295 331 if ( 296 332 String(e.message).toLowerCase().includes('token has expired') || ··· 308 344 } 309 345 }, 310 346 [ 311 - selectedAccount.did, 347 + selectedAccountDid, 348 + accounts, 312 349 closeComposer, 313 350 requestSwitchToAccount, 314 351 _, ··· 854 891 onClearVideo={clearVideo} 855 892 onPublish={onComposerPostPublish} 856 893 onError={setError} 857 - selectedAccount={selectedAccount} 894 + selectedAccountDid={selectedAccountDid} 858 895 onSelectAccount={onSelectAccount} 859 896 profiles={profiles?.profiles} 860 897 /> ··· 895 932 onSelectVideo, 896 933 onError, 897 934 onPublish, 898 - selectedAccount, 935 + selectedAccountDid, 899 936 onSelectAccount, 900 937 profiles, 901 938 }: { ··· 913 950 onSelectVideo: (postId: string, asset: ImagePickerAsset) => void 914 951 onError: (error: string) => void 915 952 onPublish: (richtext: RichText) => void 916 - selectedAccount: SessionAccount 917 - onSelectAccount: (account: SessionAccount) => void 953 + selectedAccountDid: string 954 + onSelectAccount: (accountDid: string) => void 918 955 profiles: AppBskyActorDefs.ProfileViewDetailed[] | undefined 919 956 }) { 920 957 const {_} = useLingui() ··· 996 1033 ]}> 997 1034 <View style={[a.flex_row, a.align_start, isNative && a.flex_1]}> 998 1035 <AccountSwitcher 999 - selectedAccount={selectedAccount} 1036 + selectedAccountDid={selectedAccountDid} 1000 1037 onSelectAccount={onSelectAccount} 1001 1038 profiles={profiles} 1002 1039 />
+7 -7
src/view/com/composer/account-switcher/AccountSwitcher.tsx
··· 10 10 import {SwitchAccountDialog} from '../SwitchAccount' 11 11 12 12 interface AccountSwitcherProps { 13 - selectedAccount: SessionAccount 14 - onSelectAccount: (account: SessionAccount) => void 13 + selectedAccountDid: string 14 + onSelectAccount: (accountDid: string) => void 15 15 profiles: AppBskyActorDefs.ProfileViewDetailed[] | undefined 16 16 } 17 17 18 18 export const AccountSwitcher: React.FC<AccountSwitcherProps> = ({ 19 - selectedAccount, 19 + selectedAccountDid, 20 20 onSelectAccount, 21 21 profiles, 22 22 }) => { 23 23 const {accounts} = useSession() 24 24 const {_} = useLingui() 25 - const currentProfile = profiles?.find(p => p.did === selectedAccount.did) 25 + const currentProfile = profiles?.find(p => p.did === selectedAccountDid) 26 26 const otherAccounts = accounts 27 - .filter((acc: SessionAccount) => acc.did !== selectedAccount.did) 27 + .filter((acc: SessionAccount) => acc.did !== selectedAccountDid) 28 28 .map((account: SessionAccount) => ({ 29 29 account, 30 30 profile: profiles?.find(p => p.did === account.did), ··· 48 48 </Button> 49 49 <SwitchAccountDialog 50 50 control={switchAccountControl} 51 - onSelectAccount={onSelectAccount} 52 - currentAccountDid={selectedAccount.did} 51 + onSelectAccount={account => onSelectAccount(account.did)} 52 + currentAccountDid={selectedAccountDid} 53 53 /> 54 54 </> 55 55 )
+6 -6
src/view/com/composer/account-switcher/AccountSwitcher.web.tsx
··· 12 12 import * as Menu from '#/components/Menu' 13 13 14 14 interface AccountSwitcherProps { 15 - selectedAccount: SessionAccount 16 - onSelectAccount: (account: SessionAccount) => void 15 + selectedAccountDid: string 16 + onSelectAccount: (accountDid: string) => void 17 17 profiles: AppBskyActorDefs.ProfileViewDetailed[] | undefined 18 18 } 19 19 20 20 export const AccountSwitcher: React.FC<AccountSwitcherProps> = ({ 21 - selectedAccount, 21 + selectedAccountDid, 22 22 onSelectAccount, 23 23 profiles, 24 24 }) => { 25 25 const {accounts} = useSession() 26 26 const {_} = useLingui() 27 - const currentProfile = profiles?.find(p => p.did === selectedAccount.did) 27 + const currentProfile = profiles?.find(p => p.did === selectedAccountDid) 28 28 const otherAccounts = accounts 29 - .filter((acc: SessionAccount) => acc.did !== selectedAccount.did) 29 + .filter((acc: SessionAccount) => acc.did !== selectedAccountDid) 30 30 .map((account: SessionAccount) => ({ 31 31 account, 32 32 profile: profiles?.find(p => p.did === account.did), ··· 66 66 '@', 67 67 )}`, 68 68 )} 69 - onPress={() => onSelectAccount(account)}> 69 + onPress={() => onSelectAccount(account.did)}> 70 70 <View> 71 71 <UserAvatar 72 72 avatar={profile?.avatar}