Create global keyboard shortcut handler (#10145)
This commit is contained in:
@@ -7,6 +7,7 @@ import {
|
||||
useState,
|
||||
} from 'react'
|
||||
|
||||
import {useHotkeysContext} from '#/lib/hotkeys'
|
||||
import {type DialogControlRefProps} from '#/components/Dialog'
|
||||
import {Provider as GlobalDialogsProvider} from '#/components/dialogs/Context'
|
||||
import {IS_WEB} from '#/env'
|
||||
@@ -62,6 +63,7 @@ export function useDialogFullyExpandedCountContext() {
|
||||
|
||||
export function Provider({children}: React.PropsWithChildren<{}>) {
|
||||
const [fullyExpandedCount, setFullyExpandedCount] = useState(0)
|
||||
const {disableScope, enableScope} = useHotkeysContext()
|
||||
|
||||
const activeDialogs = useRef<
|
||||
Map<string, React.MutableRefObject<DialogControlRefProps>>
|
||||
@@ -77,18 +79,26 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
|
||||
|
||||
return openDialogs.current.size > 0
|
||||
} else {
|
||||
BottomSheetNativeComponent.dismissAll()
|
||||
void BottomSheetNativeComponent.dismissAll()
|
||||
return false
|
||||
}
|
||||
}, [])
|
||||
|
||||
const setDialogIsOpen = useCallback((id: string, isOpen: boolean) => {
|
||||
if (isOpen) {
|
||||
openDialogs.current.add(id)
|
||||
} else {
|
||||
openDialogs.current.delete(id)
|
||||
}
|
||||
}, [])
|
||||
const setDialogIsOpen = useCallback(
|
||||
(id: string, isOpen: boolean) => {
|
||||
if (isOpen) {
|
||||
openDialogs.current.add(id)
|
||||
} else {
|
||||
openDialogs.current.delete(id)
|
||||
}
|
||||
if (openDialogs.current.size > 0) {
|
||||
disableScope('global')
|
||||
} else {
|
||||
enableScope('global')
|
||||
}
|
||||
},
|
||||
[disableScope, enableScope],
|
||||
)
|
||||
|
||||
const context = useMemo<IDialogContext>(
|
||||
() => ({
|
||||
|
||||
Reference in New Issue
Block a user