mirror of
https://github.com/supermemoryai/supermemory.git
synced 2026-08-28 05:25:33 +00:00
Merge pull request #187 from tushar-daiya/keymaps/addmemory
Add useKeyPress hook for keyboard event handling
This commit is contained in:
commit
1465bca983
2 changed files with 21 additions and 1 deletions
|
|
@ -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,
|
||||
|
|
|
|||
15
apps/web/lib/useKeyPress.ts
Normal file
15
apps/web/lib/useKeyPress.ts
Normal file
|
|
@ -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]);
|
||||
};
|
||||
Loading…
Add table
Reference in a new issue