summaryrefslogtreecommitdiff
path: root/apps/web/src/hooks
diff options
context:
space:
mode:
authorAnwarul Islam <anwaarulislaam@gmail.com>2025-07-18 08:05:02 +0600
committerAnwarul Islam <anwaarulislaam@gmail.com>2025-07-18 08:05:02 +0600
commit8e4661951d214f917357caef9d2895f2a4f7eb1e (patch)
treec596f664763bbc75f6afdf61d0aff70aab905821 /apps/web/src/hooks
parentcdae10ca0aeaf23d49591cb81fe9dac7b83ff642 (diff)
downloadopencut-8e4661951d214f917357caef9d2895f2a4f7eb1e.tar.gz
feat: enhance keybinding management by integrating keybindingsEnabled state and updating related hooks
Diffstat (limited to 'apps/web/src/hooks')
-rw-r--r--apps/web/src/hooks/use-keybindings.ts22
1 files changed, 5 insertions, 17 deletions
diff --git a/apps/web/src/hooks/use-keybindings.ts b/apps/web/src/hooks/use-keybindings.ts
index 6c7c0d06..7887f3f1 100644
--- a/apps/web/src/hooks/use-keybindings.ts
+++ b/apps/web/src/hooks/use-keybindings.ts
@@ -1,21 +1,15 @@
import { useEffect } from "react";
-import { ActionWithOptionalArgs, invokeAction } from "../constants/actions";
+import { invokeAction } from "../constants/actions";
import { useKeybindingsStore } from "@/stores/keybindings-store";
/**
- * This variable keeps track whether keybindings are being accepted
- * true -> Keybindings are checked
- * false -> Key presses are ignored (Keybindings are not checked)
- */
-let keybindingsEnabled = true;
-
-/**
* A composable that hooks to the caller component's
* lifecycle and hooks to the keyboard events to fire
* the appropriate actions based on keybindings
*/
export function useKeybindingsListener() {
- const { keybindings, getKeybindingString } = useKeybindingsStore();
+ const { keybindings, getKeybindingString, keybindingsEnabled } =
+ useKeybindingsStore();
useEffect(() => {
const handleKeyDown = (ev: KeyboardEvent) => {
@@ -51,20 +45,14 @@ export function useKeybindingsListener() {
return () => {
document.removeEventListener("keydown", handleKeyDown);
};
- }, [keybindings, getKeybindingString]);
+ }, [keybindings, getKeybindingString, keybindingsEnabled]);
}
/**
* This composable allows for the UI component to be disabled if the component in question is mounted
*/
export function useKeybindingDisabler() {
- const disableKeybindings = () => {
- keybindingsEnabled = false;
- };
-
- const enableKeybindings = () => {
- keybindingsEnabled = true;
- };
+ const { disableKeybindings, enableKeybindings } = useKeybindingsStore();
return {
disableKeybindings,