Bluesky app fork with some witchin' additions 💫

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

authored by

Eric Bailey and committed by
GitHub
e767c50f d76f9abd

+16 -1
+16 -1
src/state/shell/composer/useComposerKeyboardShortcut.tsx
··· 1 1 import React from 'react' 2 2 3 + import {useDialogStateContext} from '#/state/dialogs' 4 + import {useLightbox} from '#/state/lightbox' 5 + import {useModals} from '#/state/modals' 6 + import {useIsDrawerOpen} from '#/state/shell/drawer-open' 3 7 import {useComposerControls} from './' 4 8 5 9 /** ··· 35 39 36 40 export function useComposerKeyboardShortcut() { 37 41 const {openComposer} = useComposerControls() 42 + const {openDialogs} = useDialogStateContext() 43 + const {isModalActive} = useModals() 44 + const {activeLightbox} = useLightbox() 45 + const isDrawerOpen = useIsDrawerOpen() 38 46 39 47 React.useEffect(() => { 40 48 function handler(event: KeyboardEvent) { 41 49 if (shouldIgnore(event)) return 50 + if ( 51 + openDialogs.current.size > 0 || 52 + isModalActive || 53 + activeLightbox || 54 + isDrawerOpen 55 + ) 56 + return 42 57 if (event.key === 'n' || event.key === 'N') { 43 58 openComposer({}) 44 59 } 45 60 } 46 61 document.addEventListener('keydown', handler) 47 62 return () => document.removeEventListener('keydown', handler) 48 - }, [openComposer]) 63 + }, [openComposer, isModalActive, openDialogs, activeLightbox, isDrawerOpen]) 49 64 }