aboutsummaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
authorDhravya Shah <[email protected]>2024-07-29 20:19:08 -0700
committerGitHub <[email protected]>2024-07-29 20:19:08 -0700
commit1465bca98337ce47e0b1370a0b8b18e1efb7ad41 (patch)
tree1a5f2d5e111d8bfceee5a4822cf7a21f672f0292 /apps
parentfix ids not present in storecontent (diff)
parentAdd useKeyPress hook for keyboard event handling (diff)
downloadsupermemory-1465bca98337ce47e0b1370a0b8b18e1efb7ad41.tar.xz
supermemory-1465bca98337ce47e0b1370a0b8b18e1efb7ad41.zip
Merge pull request #187 from tushar-daiya/keymaps/addmemory
Add useKeyPress hook for keyboard event handling
Diffstat (limited to 'apps')
-rw-r--r--apps/web/app/(dash)/menu.tsx7
-rw-r--r--apps/web/lib/useKeyPress.ts15
2 files changed, 21 insertions, 1 deletions
diff --git a/apps/web/app/(dash)/menu.tsx b/apps/web/app/(dash)/menu.tsx
index 70439c7d..c1173eb6 100644
--- a/apps/web/app/(dash)/menu.tsx
+++ b/apps/web/app/(dash)/menu.tsx
@@ -30,6 +30,7 @@ import { createMemory, createSpace } from "../actions/doers";
import ComboboxWithCreate from "@repo/ui/shadcn/combobox";
import { StoredSpace } from "@/server/db/schema";
import useMeasure from "react-use-measure";
+import { useKeyPress } from "@/lib/useKeyPress";
function Menu() {
const [spaces, setSpaces] = useState<StoredSpace[]>([]);
@@ -48,7 +49,11 @@ function Menu() {
setSpaces(spaces.data);
})();
}, []);
-
+ useKeyPress("a", () => {
+ if (!dialogOpen) {
+ setDialogOpen(true);
+ }
+ });
const menuItems = [
{
icon: HomeIconWeb,
diff --git a/apps/web/lib/useKeyPress.ts b/apps/web/lib/useKeyPress.ts
new file mode 100644
index 00000000..eee23acb
--- /dev/null
+++ b/apps/web/lib/useKeyPress.ts
@@ -0,0 +1,15 @@
+import { useEffect } from "react";
+
+export const useKeyPress = (key: string, callback: () => void) => {
+ useEffect(() => {
+ const handler = (e: KeyboardEvent) => {
+ if (e.key === key && e.altKey) {
+ callback();
+ }
+ };
+ window.addEventListener("keydown", handler);
+ return () => {
+ window.removeEventListener("keydown", handler);
+ };
+ }, [key, callback]);
+};