Bluesky app fork with some witchin' additions 💫
0
fork

Configure Feed

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

properly close the switch account dialog (#3558)

* properly close the switch account dialog

* use it for switch account as well

* ensure dialog is closed on unmount

Revert "properly check if the ref is null"

This reverts commit 8f563808a5d39389b0bc47a31e73cd147d1e7e8b.

properly check if the ref is null

ensure dialog is closed on unmount

* Revert "ensure dialog is closed on unmount"

This reverts commit a48548fd8ed53ae3eb08a0e05bb89f641c112b95.

authored by

Hailey and committed by
GitHub
1a4e05e9 f49d73dd

+13 -22
+9 -8
src/components/dialogs/SwitchAccount.tsx
··· 6 6 import {useAccountSwitcher} from '#/lib/hooks/useAccountSwitcher' 7 7 import {type SessionAccount, useSession} from '#/state/session' 8 8 import {useLoggedOutViewControls} from '#/state/shell/logged-out' 9 - import {useCloseAllActiveElements} from '#/state/util' 10 9 import {atoms as a} from '#/alf' 11 10 import * as Dialog from '#/components/Dialog' 12 11 import {AccountList} from '../AccountList' ··· 21 20 const {currentAccount} = useSession() 22 21 const {onPressSwitchAccount} = useAccountSwitcher() 23 22 const {setShowLoggedOut} = useLoggedOutViewControls() 24 - const closeAllActiveElements = useCloseAllActiveElements() 25 23 26 24 const onSelectAccount = useCallback( 27 25 (account: SessionAccount) => { 28 - if (account.did === currentAccount?.did) { 29 - control.close() 26 + if (account.did !== currentAccount?.did) { 27 + control.close(() => { 28 + onPressSwitchAccount(account, 'SwitchAccount') 29 + }) 30 30 } else { 31 - onPressSwitchAccount(account, 'SwitchAccount') 31 + control.close() 32 32 } 33 33 }, 34 34 [currentAccount, control, onPressSwitchAccount], 35 35 ) 36 36 37 37 const onPressAddAccount = useCallback(() => { 38 - setShowLoggedOut(true) 39 - closeAllActiveElements() 40 - }, [setShowLoggedOut, closeAllActiveElements]) 38 + control.close(() => { 39 + setShowLoggedOut(true) 40 + }) 41 + }, [setShowLoggedOut, control]) 41 42 42 43 return ( 43 44 <Dialog.Outer control={control}>
+4 -14
src/lib/hooks/useAccountSwitcher.ts
··· 1 1 import {useCallback} from 'react' 2 2 3 + import {useAnalytics} from '#/lib/analytics/analytics' 3 4 import {isWeb} from '#/platform/detection' 4 - import {useAnalytics} from '#/lib/analytics/analytics' 5 - import {useSessionApi, SessionAccount} from '#/state/session' 5 + import {SessionAccount, useSessionApi} from '#/state/session' 6 + import {useLoggedOutViewControls} from '#/state/shell/logged-out' 6 7 import * as Toast from '#/view/com/util/Toast' 7 - import {useCloseAllActiveElements} from '#/state/util' 8 - import {useLoggedOutViewControls} from '#/state/shell/logged-out' 9 8 import {LogEvents} from '../statsig/statsig' 10 9 11 10 export function useAccountSwitcher() { 12 11 const {track} = useAnalytics() 13 12 const {selectAccount, clearCurrentAccount} = useSessionApi() 14 - const closeAllActiveElements = useCloseAllActiveElements() 15 13 const {requestSwitchToAccount} = useLoggedOutViewControls() 16 14 17 15 const onPressSwitchAccount = useCallback( ··· 23 21 24 22 try { 25 23 if (account.accessJwt) { 26 - closeAllActiveElements() 27 24 if (isWeb) { 28 25 // We're switching accounts, which remounts the entire app. 29 26 // On mobile, this gets us Home, but on the web we also need reset the URL. ··· 37 34 Toast.show(`Signed in as @${account.handle}`) 38 35 }, 100) 39 36 } else { 40 - closeAllActiveElements() 41 37 requestSwitchToAccount({requestedAccount: account.did}) 42 38 Toast.show( 43 39 `Please sign in as @${account.handle}`, ··· 49 45 clearCurrentAccount() // back user out to login 50 46 } 51 47 }, 52 - [ 53 - track, 54 - clearCurrentAccount, 55 - selectAccount, 56 - closeAllActiveElements, 57 - requestSwitchToAccount, 58 - ], 48 + [track, clearCurrentAccount, selectAccount, requestSwitchToAccount], 59 49 ) 60 50 61 51 return {onPressSwitchAccount}