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
zio/dev^2
Eric Bailey 2024-09-13 18:14:46 -05:00 committed by GitHub
parent d76f9abdd7
commit e767c50f65
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 16 additions and 1 deletions

View File

@ -1,5 +1,9 @@
import React from 'react' 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 './' import {useComposerControls} from './'
/** /**
@ -35,15 +39,26 @@ function shouldIgnore(event: KeyboardEvent) {
export function useComposerKeyboardShortcut() { export function useComposerKeyboardShortcut() {
const {openComposer} = useComposerControls() const {openComposer} = useComposerControls()
const {openDialogs} = useDialogStateContext()
const {isModalActive} = useModals()
const {activeLightbox} = useLightbox()
const isDrawerOpen = useIsDrawerOpen()
React.useEffect(() => { React.useEffect(() => {
function handler(event: KeyboardEvent) { function handler(event: KeyboardEvent) {
if (shouldIgnore(event)) return if (shouldIgnore(event)) return
if (
openDialogs.current.size > 0 ||
isModalActive ||
activeLightbox ||
isDrawerOpen
)
return
if (event.key === 'n' || event.key === 'N') { if (event.key === 'n' || event.key === 'N') {
openComposer({}) openComposer({})
} }
} }
document.addEventListener('keydown', handler) document.addEventListener('keydown', handler)
return () => document.removeEventListener('keydown', handler) return () => document.removeEventListener('keydown', handler)
}, [openComposer]) }, [openComposer, isModalActive, openDialogs, activeLightbox, isDrawerOpen])
} }