properly close the switch account dialog
This commit is contained in:
@@ -25,10 +25,12 @@ export function SwitchAccountDialog({
|
|||||||
|
|
||||||
const onSelectAccount = useCallback(
|
const onSelectAccount = useCallback(
|
||||||
(account: SessionAccount) => {
|
(account: SessionAccount) => {
|
||||||
if (account.did === currentAccount?.did) {
|
if (account.did !== currentAccount?.did) {
|
||||||
control.close()
|
control.close(() => {
|
||||||
} else {
|
|
||||||
onPressSwitchAccount(account, 'SwitchAccount')
|
onPressSwitchAccount(account, 'SwitchAccount')
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
control.close()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[currentAccount, control, onPressSwitchAccount],
|
[currentAccount, control, onPressSwitchAccount],
|
||||||
|
|||||||
@@ -1,17 +1,15 @@
|
|||||||
import {useCallback} from 'react'
|
import {useCallback} from 'react'
|
||||||
|
|
||||||
import {isWeb} from '#/platform/detection'
|
|
||||||
import {useAnalytics} from '#/lib/analytics/analytics'
|
import {useAnalytics} from '#/lib/analytics/analytics'
|
||||||
import {useSessionApi, SessionAccount} from '#/state/session'
|
import {isWeb} from '#/platform/detection'
|
||||||
import * as Toast from '#/view/com/util/Toast'
|
import {SessionAccount, useSessionApi} from '#/state/session'
|
||||||
import {useCloseAllActiveElements} from '#/state/util'
|
|
||||||
import {useLoggedOutViewControls} from '#/state/shell/logged-out'
|
import {useLoggedOutViewControls} from '#/state/shell/logged-out'
|
||||||
|
import * as Toast from '#/view/com/util/Toast'
|
||||||
import {LogEvents} from '../statsig/statsig'
|
import {LogEvents} from '../statsig/statsig'
|
||||||
|
|
||||||
export function useAccountSwitcher() {
|
export function useAccountSwitcher() {
|
||||||
const {track} = useAnalytics()
|
const {track} = useAnalytics()
|
||||||
const {selectAccount, clearCurrentAccount} = useSessionApi()
|
const {selectAccount, clearCurrentAccount} = useSessionApi()
|
||||||
const closeAllActiveElements = useCloseAllActiveElements()
|
|
||||||
const {requestSwitchToAccount} = useLoggedOutViewControls()
|
const {requestSwitchToAccount} = useLoggedOutViewControls()
|
||||||
|
|
||||||
const onPressSwitchAccount = useCallback(
|
const onPressSwitchAccount = useCallback(
|
||||||
@@ -23,7 +21,6 @@ export function useAccountSwitcher() {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
if (account.accessJwt) {
|
if (account.accessJwt) {
|
||||||
closeAllActiveElements()
|
|
||||||
if (isWeb) {
|
if (isWeb) {
|
||||||
// We're switching accounts, which remounts the entire app.
|
// 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.
|
// On mobile, this gets us Home, but on the web we also need reset the URL.
|
||||||
@@ -37,7 +34,6 @@ export function useAccountSwitcher() {
|
|||||||
Toast.show(`Signed in as @${account.handle}`)
|
Toast.show(`Signed in as @${account.handle}`)
|
||||||
}, 100)
|
}, 100)
|
||||||
} else {
|
} else {
|
||||||
closeAllActiveElements()
|
|
||||||
requestSwitchToAccount({requestedAccount: account.did})
|
requestSwitchToAccount({requestedAccount: account.did})
|
||||||
Toast.show(
|
Toast.show(
|
||||||
`Please sign in as @${account.handle}`,
|
`Please sign in as @${account.handle}`,
|
||||||
@@ -49,13 +45,7 @@ export function useAccountSwitcher() {
|
|||||||
clearCurrentAccount() // back user out to login
|
clearCurrentAccount() // back user out to login
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[
|
[track, clearCurrentAccount, selectAccount, requestSwitchToAccount],
|
||||||
track,
|
|
||||||
clearCurrentAccount,
|
|
||||||
selectAccount,
|
|
||||||
closeAllActiveElements,
|
|
||||||
requestSwitchToAccount,
|
|
||||||
],
|
|
||||||
)
|
)
|
||||||
|
|
||||||
return {onPressSwitchAccount}
|
return {onPressSwitchAccount}
|
||||||
|
|||||||
Reference in New Issue
Block a user