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
45
src/state/util.ts
Normal file
45
src/state/util.ts
Normal file
|
@ -0,0 +1,45 @@
|
|||
import {useCallback} from 'react'
|
||||
import {useLightboxControls} from './lightbox'
|
||||
import {useModalControls} from './modals'
|
||||
import {useComposerControls} from './shell/composer'
|
||||
import {useSetDrawerOpen} from './shell/drawer-open'
|
||||
|
||||
/**
|
||||
* returns true if something was closed
|
||||
* (used by the android hardware back btn)
|
||||
*/
|
||||
export function useCloseAnyActiveElement() {
|
||||
const {closeLightbox} = useLightboxControls()
|
||||
const {closeModal} = useModalControls()
|
||||
const {closeComposer} = useComposerControls()
|
||||
const setDrawerOpen = useSetDrawerOpen()
|
||||
return useCallback(() => {
|
||||
if (closeLightbox()) {
|
||||
return true
|
||||
}
|
||||
if (closeModal()) {
|
||||
return true
|
||||
}
|
||||
if (closeComposer()) {
|
||||
return true
|
||||
}
|
||||
setDrawerOpen(false)
|
||||
return false
|
||||
}, [closeLightbox, closeModal, closeComposer, setDrawerOpen])
|
||||
}
|
||||
|
||||
/**
|
||||
* used to clear out any modals, eg for a navigation
|
||||
*/
|
||||
export function useCloseAllActiveElements() {
|
||||
const {closeLightbox} = useLightboxControls()
|
||||
const {closeAllModals} = useModalControls()
|
||||
const {closeComposer} = useComposerControls()
|
||||
const setDrawerOpen = useSetDrawerOpen()
|
||||
return useCallback(() => {
|
||||
closeLightbox()
|
||||
closeAllModals()
|
||||
closeComposer()
|
||||
setDrawerOpen(false)
|
||||
}, [closeLightbox, closeAllModals, closeComposer, setDrawerOpen])
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue