Close active elems (react-query refactor) (#1926)
* Refactor closeAny and closeAllActiveElements * Add close lightbox * Switch to hooks * Fixes
This commit is contained in:
parent
0de8d40981
commit
a84b2f9f2f
9 changed files with 101 additions and 66 deletions
|
@ -1,18 +1,13 @@
|
|||
import {useCallback} from 'react'
|
||||
|
||||
import {useAnalytics} from '#/lib/analytics/analytics'
|
||||
import {useStores} from '#/state/index'
|
||||
import {useSetDrawerOpen} from '#/state/shell/drawer-open'
|
||||
import {useModalControls} from '#/state/modals'
|
||||
import {useSessionApi, SessionAccount} from '#/state/session'
|
||||
import * as Toast from '#/view/com/util/Toast'
|
||||
import {useCloseAllActiveElements} from '#/state/util'
|
||||
|
||||
export function useAccountSwitcher() {
|
||||
const {track} = useAnalytics()
|
||||
const store = useStores()
|
||||
const setDrawerOpen = useSetDrawerOpen()
|
||||
const {closeModal} = useModalControls()
|
||||
const {selectAccount, clearCurrentAccount} = useSessionApi()
|
||||
const closeAllActiveElements = useCloseAllActiveElements()
|
||||
|
||||
const onPressSwitchAccount = useCallback(
|
||||
async (acct: SessionAccount) => {
|
||||
|
@ -20,23 +15,14 @@ export function useAccountSwitcher() {
|
|||
|
||||
try {
|
||||
await selectAccount(acct)
|
||||
setDrawerOpen(false)
|
||||
closeModal()
|
||||
store.shell.closeAllActiveElements()
|
||||
closeAllActiveElements()
|
||||
Toast.show(`Signed in as ${acct.handle}`)
|
||||
} catch (e) {
|
||||
Toast.show('Sorry! We need you to enter your password.')
|
||||
clearCurrentAccount() // back user out to login
|
||||
}
|
||||
},
|
||||
[
|
||||
track,
|
||||
store,
|
||||
setDrawerOpen,
|
||||
closeModal,
|
||||
clearCurrentAccount,
|
||||
selectAccount,
|
||||
],
|
||||
[track, clearCurrentAccount, selectAccount, closeAllActiveElements],
|
||||
)
|
||||
|
||||
return {onPressSwitchAccount}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue