mirror of
https://github.com/infinilabs/coco-app.git
synced 2025-12-25 15:59:30 +01:00
30 lines
760 B
TypeScript
30 lines
760 B
TypeScript
import { POPOVER_PANEL_SELECTOR } from "@/constants";
|
|
import { useShortcutsStore } from "@/stores/shortcutsStore";
|
|
import { useKeyPress } from "ahooks";
|
|
|
|
export const useModifierKeyPress = () => {
|
|
const modifierKey = useShortcutsStore((state) => {
|
|
return state.modifierKey;
|
|
});
|
|
const setModifierKeyPressed = useShortcutsStore((state) => {
|
|
return state.setModifierKeyPressed;
|
|
});
|
|
const setOpenPopover = useShortcutsStore((state) => {
|
|
return state.setOpenPopover;
|
|
});
|
|
|
|
useKeyPress(
|
|
modifierKey,
|
|
(event) => {
|
|
const el = document.querySelector(POPOVER_PANEL_SELECTOR);
|
|
|
|
setOpenPopover(Boolean(el));
|
|
|
|
setModifierKeyPressed(event.type === "keydown");
|
|
},
|
|
{
|
|
events: ["keydown", "keyup"],
|
|
}
|
|
);
|
|
};
|