diff options
author | dan <dan.abramov@gmail.com> | 2023-12-07 22:28:49 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-07 14:28:49 -0800 |
commit | 794015aef88b4488e9803e76908c00fdb53b0df2 (patch) | |
tree | e0135ea375b1660f39206a56a70dc9d09375d42e /src/lib/hooks/useAccountSwitcher.ts | |
parent | 1b5989ac51328b47779dffb7672e9d04885e43b0 (diff) | |
download | voidsky-794015aef88b4488e9803e76908c00fdb53b0df2.tar.zst |
Navigate Home on account switch (#2138)
Diffstat (limited to 'src/lib/hooks/useAccountSwitcher.ts')
-rw-r--r-- | src/lib/hooks/useAccountSwitcher.ts | 19 |
1 files changed, 7 insertions, 12 deletions
diff --git a/src/lib/hooks/useAccountSwitcher.ts b/src/lib/hooks/useAccountSwitcher.ts index f67a586ef..2f2c110d9 100644 --- a/src/lib/hooks/useAccountSwitcher.ts +++ b/src/lib/hooks/useAccountSwitcher.ts @@ -1,8 +1,6 @@ import {useCallback} from 'react' -import {useNavigation} from '@react-navigation/native' import {isWeb} from '#/platform/detection' -import {NavigationProp} from '#/lib/routes/types' import {useAnalytics} from '#/lib/analytics/analytics' import {useSessionApi, SessionAccount} from '#/state/session' import * as Toast from '#/view/com/util/Toast' @@ -13,7 +11,6 @@ export function useAccountSwitcher() { const {track} = useAnalytics() const {selectAccount, clearCurrentAccount} = useSessionApi() const closeAllActiveElements = useCloseAllActiveElements() - const navigation = useNavigation<NavigationProp>() const {setShowLoggedOut} = useLoggedOutViewControls() const onPressSwitchAccount = useCallback( @@ -23,16 +20,15 @@ export function useAccountSwitcher() { try { if (account.accessJwt) { closeAllActiveElements() - await selectAccount(account) - - /* - * Mobile resets to Home on its own, so no need to handle mobile - * specifically. - */ if (isWeb) { - navigation.navigate('Home') + // We're switching accounts, which remounts the entire app. + // On mobile, this gets us Home, but on the web we also need reset the URL. + // We can't change the URL via a navigate() call because the navigator + // itself is about to unmount, and it calls pushState() too late. + // So we change the URL ourselves. The navigator will pick it up on remount. + history.pushState(null, '', '/') } - + await selectAccount(account) setTimeout(() => { Toast.show(`Signed in as @${account.handle}`) }, 100) @@ -54,7 +50,6 @@ export function useAccountSwitcher() { clearCurrentAccount, selectAccount, closeAllActiveElements, - navigation, setShowLoggedOut, ], ) |