Skip to content

Commit

Permalink
bug fix #507
Browse files Browse the repository at this point in the history
  • Loading branch information
mrmatthewnguyen105 committed Dec 14, 2023
1 parent babac0e commit 578e686
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
1 change: 0 additions & 1 deletion src/pages/main/hooks/useCmdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
11 changes: 9 additions & 2 deletions src/pages/main/hooks/useCmdkModal.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect, useState } from "react";
import { useCallback, useEffect, useState } from "react";

import { useDispatch } from "react-redux";

Expand All @@ -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();
Expand All @@ -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(() => {
Expand Down

0 comments on commit 578e686

Please sign in to comment.