This commit is contained in:
Dhravya Shah 2024-07-30 08:25:57 -07:00
commit 6216f5f9d3
4 changed files with 30 additions and 2 deletions

View file

@ -131,6 +131,13 @@ export default function ContentApp({
});
}
});
const handleKeyDown = (e: KeyboardEvent) => {
if (isPopoverOpen) {
e.stopPropagation();
e.preventDefault();
}
};
document.addEventListener("keydown", handleKeyDown, true);
const portalDiv = document.createElement("div");
portalDiv.id = "popover-portal";
@ -139,6 +146,7 @@ export default function ContentApp({
return () => {
document.removeEventListener("mousemove", () => {});
document.removeEventListener("keydown", handleKeyDown, true);
};
}, []);

View file

@ -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,

View file

@ -37,7 +37,7 @@ async function page() {
</div>
<h3 className="fixed left-1/2 -translate-x-1/2 bottom-4 text-gray-400 pt-20 text-center">
*this is under beta and only one canvas is allowed per user
Thinkpads is under beta and only one thinkpad is allowed per user.
</h3>
</div>
);

View 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]);
};