Navigate Home on account switch (#2138)
parent
1b5989ac51
commit
794015aef8
|
@ -1,8 +1,6 @@
|
||||||
import {useCallback} from 'react'
|
import {useCallback} from 'react'
|
||||||
import {useNavigation} from '@react-navigation/native'
|
|
||||||
|
|
||||||
import {isWeb} from '#/platform/detection'
|
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'
|
||||||
|
@ -13,7 +11,6 @@ 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 {setShowLoggedOut} = useLoggedOutViewControls()
|
const {setShowLoggedOut} = useLoggedOutViewControls()
|
||||||
|
|
||||||
const onPressSwitchAccount = useCallback(
|
const onPressSwitchAccount = useCallback(
|
||||||
|
@ -23,16 +20,15 @@ export function useAccountSwitcher() {
|
||||||
try {
|
try {
|
||||||
if (account.accessJwt) {
|
if (account.accessJwt) {
|
||||||
closeAllActiveElements()
|
closeAllActiveElements()
|
||||||
await selectAccount(account)
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Mobile resets to Home on its own, so no need to handle mobile
|
|
||||||
* specifically.
|
|
||||||
*/
|
|
||||||
if (isWeb) {
|
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(() => {
|
setTimeout(() => {
|
||||||
Toast.show(`Signed in as @${account.handle}`)
|
Toast.show(`Signed in as @${account.handle}`)
|
||||||
}, 100)
|
}, 100)
|
||||||
|
@ -54,7 +50,6 @@ export function useAccountSwitcher() {
|
||||||
clearCurrentAccount,
|
clearCurrentAccount,
|
||||||
selectAccount,
|
selectAccount,
|
||||||
closeAllActiveElements,
|
closeAllActiveElements,
|
||||||
navigation,
|
|
||||||
setShowLoggedOut,
|
setShowLoggedOut,
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue