From ea346bb4b8811b27079033b9fa982d2ea6259300 Mon Sep 17 00:00:00 2001 From: Jason Date: Thu, 14 Dec 2023 22:02:26 +0800 Subject: [PATCH] MainPage useCmdk fix --- src/pages/main/hooks/useCmdk.ts | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/pages/main/hooks/useCmdk.ts b/src/pages/main/hooks/useCmdk.ts index b0cee78b..072aa428 100644 --- a/src/pages/main/hooks/useCmdk.ts +++ b/src/pages/main/hooks/useCmdk.ts @@ -44,6 +44,8 @@ interface IUseCmdk { ) => Promise; } export const useCmdk = ({ cmdkReferenceData, importProject }: IUseCmdk) => { + useEffect(() => {}); + const dispatch = useDispatch(); const { osType, @@ -66,12 +68,6 @@ export const useCmdk = ({ cmdkReferenceData, importProject }: IUseCmdk) => { currentCommand, } = useAppState(); - // refs - const cmdkOpenRef = useRef(false); - useEffect(() => { - cmdkOpenRef.current = cmdkOpen; - }, [cmdkOpen]); - // handlers const onClear = useCallback(async () => { window.localStorage.clear(); @@ -237,7 +233,7 @@ export const useCmdk = ({ cmdkReferenceData, importProject }: IUseCmdk) => { return; } if (e.key === "Escape") { - !cmdkOpenRef.current && closeAllPanel(); + !cmdkOpen && closeAllPanel(); return; } // skip inline rename input in file-tree-view @@ -291,13 +287,13 @@ export const useCmdk = ({ cmdkReferenceData, importProject }: IUseCmdk) => { e.preventDefault(); } - if (cmdkOpenRef.current) return; + if (cmdkOpen) return; if (action) { LogAllow && console.log("action to be run by cmdk: ", action); dispatch(setCurrentCommand({ action })); } }, - [osType, cmdkReferenceData], + [osType, cmdkOpen, cmdkReferenceData], ); useEffect(() => { document.addEventListener("keydown", KeyDownEventListener);