Navigate Home on account switch (#2138)
parent
1b5989ac51
commit
794015aef8
|
@ -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,
|
||||
],
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue