Skip to content

Commit

Permalink
MainPage useCmdk fix
Browse files Browse the repository at this point in the history
  • Loading branch information
mrmatthewnguyen105 committed Dec 14, 2023
1 parent 578e686 commit ea346bb
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions src/pages/main/hooks/useCmdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ interface IUseCmdk {
) => Promise<void>;
}
export const useCmdk = ({ cmdkReferenceData, importProject }: IUseCmdk) => {
useEffect(() => {});

const dispatch = useDispatch();
const {
osType,
Expand All @@ -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();
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit ea346bb

Please sign in to comment.