From 578e6861c4ae858c5c3f1fc5cd2f8f56358cc957 Mon Sep 17 00:00:00 2001 From: Jason Date: Thu, 14 Dec 2023 21:57:45 +0800 Subject: [PATCH] bug fix #507 --- src/pages/main/hooks/useCmdk.ts | 1 - src/pages/main/hooks/useCmdkModal.ts | 11 +++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/pages/main/hooks/useCmdk.ts b/src/pages/main/hooks/useCmdk.ts index 6d683aaf..b0cee78b 100644 --- a/src/pages/main/hooks/useCmdk.ts +++ b/src/pages/main/hooks/useCmdk.ts @@ -300,7 +300,6 @@ export const useCmdk = ({ cmdkReferenceData, importProject }: IUseCmdk) => { [osType, cmdkReferenceData], ); useEffect(() => { - console.log("keydowneventlistnere added"); document.addEventListener("keydown", KeyDownEventListener); return () => document.removeEventListener("keydown", KeyDownEventListener); }, [KeyDownEventListener]); diff --git a/src/pages/main/hooks/useCmdkModal.ts b/src/pages/main/hooks/useCmdkModal.ts index 3069c77c..0a8ebc15 100644 --- a/src/pages/main/hooks/useCmdkModal.ts +++ b/src/pages/main/hooks/useCmdkModal.ts @@ -1,4 +1,4 @@ -import { useEffect, useState } from "react"; +import { useCallback, useEffect, useState } from "react"; import { useDispatch } from "react-redux"; @@ -9,6 +9,8 @@ import { setCurrentCmdkPage, } from "@_redux/main/cmdk"; import { useAppState } from "@_redux/useAppState"; +import { debounce } from "lodash"; +import { ShortDelay } from "@_constants/main"; export const useCmdkModal = () => { const dispatch = useDispatch(); @@ -19,8 +21,13 @@ export const useCmdkModal = () => { string | null | undefined >(); + const debouncedCmdkOpen = useCallback( + debounce(() => dispatch(setCmdkOpen(true)), ShortDelay), + [], + ); useEffect(() => { - cmdkPages.length && dispatch(setCmdkOpen(true)); + cmdkPages.length && debouncedCmdkOpen(); + // cmdkPages.length && dispatch(setCmdkOpen(true)); dispatch(setCurrentCmdkPage([...cmdkPages].pop() || "")); }, [cmdkPages]); useEffect(() => {