diff options
author | Eric Bailey <git@esb.lol> | 2024-09-13 18:14:46 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-13 18:14:46 -0500 |
commit | e767c50f65b67444d320f13bdad619001df7a52b (patch) | |
tree | 6b9eb19b73402444456fa4e37d3d1eb23b8ca944 /src/state/shell/composer/useComposerKeyboardShortcut.tsx | |
parent | d76f9abdd718e24848a9b8f67486129aee421427 (diff) | |
download | voidsky-e767c50f65b67444d320f13bdad619001df7a52b.tar.zst |
Don't open composer via hotkey if other dialog is already open (#5334)
* Don't open composer via hotkey if other dialog is already open * Check for lightbox also * Check for drawer
Diffstat (limited to 'src/state/shell/composer/useComposerKeyboardShortcut.tsx')
-rw-r--r-- | src/state/shell/composer/useComposerKeyboardShortcut.tsx | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/src/state/shell/composer/useComposerKeyboardShortcut.tsx b/src/state/shell/composer/useComposerKeyboardShortcut.tsx index f46062185..0cdc6c754 100644 --- a/src/state/shell/composer/useComposerKeyboardShortcut.tsx +++ b/src/state/shell/composer/useComposerKeyboardShortcut.tsx @@ -1,5 +1,9 @@ import React from 'react' +import {useDialogStateContext} from '#/state/dialogs' +import {useLightbox} from '#/state/lightbox' +import {useModals} from '#/state/modals' +import {useIsDrawerOpen} from '#/state/shell/drawer-open' import {useComposerControls} from './' /** @@ -35,15 +39,26 @@ function shouldIgnore(event: KeyboardEvent) { export function useComposerKeyboardShortcut() { const {openComposer} = useComposerControls() + const {openDialogs} = useDialogStateContext() + const {isModalActive} = useModals() + const {activeLightbox} = useLightbox() + const isDrawerOpen = useIsDrawerOpen() React.useEffect(() => { function handler(event: KeyboardEvent) { if (shouldIgnore(event)) return + if ( + openDialogs.current.size > 0 || + isModalActive || + activeLightbox || + isDrawerOpen + ) + return if (event.key === 'n' || event.key === 'N') { openComposer({}) } } document.addEventListener('keydown', handler) return () => document.removeEventListener('keydown', handler) - }, [openComposer]) + }, [openComposer, isModalActive, openDialogs, activeLightbox, isDrawerOpen]) } |