Skip to content

Commit

Permalink
Don't open composer via hotkey if other dialog is already open (#5334)
Browse files Browse the repository at this point in the history
* Don't open composer via hotkey if other dialog is already open

* Check for lightbox also

* Check for drawer
  • Loading branch information
estrattonbailey authored Sep 13, 2024
1 parent d76f9ab commit e767c50
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/state/shell/composer/useComposerKeyboardShortcut.tsx
Original file line number Diff line number Diff line change
@@ -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 './'

/**
Expand Down Expand Up @@ -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])
}

0 comments on commit e767c50

Please sign in to comment.