Nav home after switch accounts (#2002)
parent
828e53d533
commit
6758755316
|
@ -1,4 +1,8 @@
|
||||||
import {useCallback} from 'react'
|
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 {useAnalytics} from '#/lib/analytics/analytics'
|
||||||
import {useSessionApi, SessionAccount} from '#/state/session'
|
import {useSessionApi, SessionAccount} from '#/state/session'
|
||||||
import * as Toast from '#/view/com/util/Toast'
|
import * as Toast from '#/view/com/util/Toast'
|
||||||
|
@ -8,21 +12,29 @@ export function useAccountSwitcher() {
|
||||||
const {track} = useAnalytics()
|
const {track} = useAnalytics()
|
||||||
const {selectAccount, clearCurrentAccount} = useSessionApi()
|
const {selectAccount, clearCurrentAccount} = useSessionApi()
|
||||||
const closeAllActiveElements = useCloseAllActiveElements()
|
const closeAllActiveElements = useCloseAllActiveElements()
|
||||||
|
const navigation = useNavigation<NavigationProp>()
|
||||||
|
|
||||||
const onPressSwitchAccount = useCallback(
|
const onPressSwitchAccount = useCallback(
|
||||||
async (acct: SessionAccount) => {
|
async (acct: SessionAccount) => {
|
||||||
track('Settings:SwitchAccountButtonClicked')
|
track('Settings:SwitchAccountButtonClicked')
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await selectAccount(acct)
|
|
||||||
closeAllActiveElements()
|
closeAllActiveElements()
|
||||||
|
navigation.navigate(isWeb ? 'Home' : 'HomeTab')
|
||||||
|
await selectAccount(acct)
|
||||||
Toast.show(`Signed in as ${acct.handle}`)
|
Toast.show(`Signed in as ${acct.handle}`)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
Toast.show('Sorry! We need you to enter your password.')
|
Toast.show('Sorry! We need you to enter your password.')
|
||||||
clearCurrentAccount() // back user out to login
|
clearCurrentAccount() // back user out to login
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[track, clearCurrentAccount, selectAccount, closeAllActiveElements],
|
[
|
||||||
|
track,
|
||||||
|
clearCurrentAccount,
|
||||||
|
selectAccount,
|
||||||
|
closeAllActiveElements,
|
||||||
|
navigation,
|
||||||
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
return {onPressSwitchAccount}
|
return {onPressSwitchAccount}
|
||||||
|
|
Loading…
Reference in New Issue