about summary refs log tree commit diff
path: root/src/lib/hooks/useAccountSwitcher.ts
diff options
context:
space:
mode:
authorEric Bailey <git@esb.lol>2023-11-27 12:27:38 -0600
committerGitHub <noreply@github.com>2023-11-27 10:27:38 -0800
commit675875531623750d0063db0aff8ec2580461e20b (patch)
treef4b0c2ddac8f027a8e210bbcd276d2bd7fceafbe /src/lib/hooks/useAccountSwitcher.ts
parent828e53d53316b539b21a02cf252ccd5ff0c3e413 (diff)
downloadvoidsky-675875531623750d0063db0aff8ec2580461e20b.tar.zst
Nav home after switch accounts (#2002)
Diffstat (limited to 'src/lib/hooks/useAccountSwitcher.ts')
-rw-r--r--src/lib/hooks/useAccountSwitcher.ts16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/lib/hooks/useAccountSwitcher.ts b/src/lib/hooks/useAccountSwitcher.ts
index a4c800667..82f4565e9 100644
--- a/src/lib/hooks/useAccountSwitcher.ts
+++ b/src/lib/hooks/useAccountSwitcher.ts
@@ -1,4 +1,8 @@
 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'
@@ -8,21 +12,29 @@ export function useAccountSwitcher() {
   const {track} = useAnalytics()
   const {selectAccount, clearCurrentAccount} = useSessionApi()
   const closeAllActiveElements = useCloseAllActiveElements()
+  const navigation = useNavigation<NavigationProp>()
 
   const onPressSwitchAccount = useCallback(
     async (acct: SessionAccount) => {
       track('Settings:SwitchAccountButtonClicked')
 
       try {
-        await selectAccount(acct)
         closeAllActiveElements()
+        navigation.navigate(isWeb ? 'Home' : 'HomeTab')
+        await selectAccount(acct)
         Toast.show(`Signed in as ${acct.handle}`)
       } catch (e) {
         Toast.show('Sorry! We need you to enter your password.')
         clearCurrentAccount() // back user out to login
       }
     },
-    [track, clearCurrentAccount, selectAccount, closeAllActiveElements],
+    [
+      track,
+      clearCurrentAccount,
+      selectAccount,
+      closeAllActiveElements,
+      navigation,
+    ],
   )
 
   return {onPressSwitchAccount}