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 drawerzio/dev^2
parent
d76f9abdd7
commit
e767c50f65
|
@ -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])
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue