From e767c50f65b67444d320f13bdad619001df7a52b Mon Sep 17 00:00:00 2001
From: Eric Bailey <git@esb.lol>
Date: Fri, 13 Sep 2024 18:14:46 -0500
Subject: 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
---
 .../shell/composer/useComposerKeyboardShortcut.tsx      | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

(limited to 'src/state/shell/composer/useComposerKeyboardShortcut.tsx')

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])
 }
-- 
cgit 1.4.1

