properly close the switch account dialog (#3558)
* properly close the switch account dialog
* use it for switch account as well
* ensure dialog is closed on unmount
Revert "properly check if the ref is null"
This reverts commit 8f563808a5d39389b0bc47a31e73cd147d1e7e8b.
properly check if the ref is null
ensure dialog is closed on unmount
* Revert "ensure dialog is closed on unmount"
This reverts commit a48548fd8e.
This commit is contained in:
@@ -6,7 +6,6 @@ import {useLingui} from '@lingui/react'
|
||||
import {useAccountSwitcher} from '#/lib/hooks/useAccountSwitcher'
|
||||
import {type SessionAccount, useSession} from '#/state/session'
|
||||
import {useLoggedOutViewControls} from '#/state/shell/logged-out'
|
||||
import {useCloseAllActiveElements} from '#/state/util'
|
||||
import {atoms as a} from '#/alf'
|
||||
import * as Dialog from '#/components/Dialog'
|
||||
import {AccountList} from '../AccountList'
|
||||
@@ -21,23 +20,25 @@ export function SwitchAccountDialog({
|
||||
const {currentAccount} = useSession()
|
||||
const {onPressSwitchAccount} = useAccountSwitcher()
|
||||
const {setShowLoggedOut} = useLoggedOutViewControls()
|
||||
const closeAllActiveElements = useCloseAllActiveElements()
|
||||
|
||||
const onSelectAccount = useCallback(
|
||||
(account: SessionAccount) => {
|
||||
if (account.did === currentAccount?.did) {
|
||||
control.close()
|
||||
if (account.did !== currentAccount?.did) {
|
||||
control.close(() => {
|
||||
onPressSwitchAccount(account, 'SwitchAccount')
|
||||
})
|
||||
} else {
|
||||
onPressSwitchAccount(account, 'SwitchAccount')
|
||||
control.close()
|
||||
}
|
||||
},
|
||||
[currentAccount, control, onPressSwitchAccount],
|
||||
)
|
||||
|
||||
const onPressAddAccount = useCallback(() => {
|
||||
setShowLoggedOut(true)
|
||||
closeAllActiveElements()
|
||||
}, [setShowLoggedOut, closeAllActiveElements])
|
||||
control.close(() => {
|
||||
setShowLoggedOut(true)
|
||||
})
|
||||
}, [setShowLoggedOut, control])
|
||||
|
||||
return (
|
||||
<Dialog.Outer control={control}>
|
||||
|
||||
Reference in New Issue
Block a user