Skip to content

Commit

Permalink
cleaner
Browse files Browse the repository at this point in the history
  • Loading branch information
Dhravya committed Jul 30, 2024
2 parents efe8781 + cf4d1a1 commit 6216f5f
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
8 changes: 8 additions & 0 deletions apps/extension/content/ContentApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -139,6 +146,7 @@ export default function ContentApp({

return () => {
document.removeEventListener("mousemove", () => {});
document.removeEventListener("keydown", handleKeyDown, true);
};
}, []);

Expand Down
7 changes: 6 additions & 1 deletion apps/web/app/(dash)/menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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[]>([]);
Expand All @@ -48,7 +49,11 @@ function Menu() {
setSpaces(spaces.data);
})();
}, []);

useKeyPress("a", () => {
if (!dialogOpen) {
setDialogOpen(true);
}
});
const menuItems = [
{
icon: HomeIconWeb,
Expand Down
2 changes: 1 addition & 1 deletion apps/web/app/(thinkpad)/thinkpad/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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>
);
Expand Down
15 changes: 15 additions & 0 deletions apps/web/lib/useKeyPress.ts
Original file line number Diff line number Diff line change
@@ -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]);
};

0 comments on commit 6216f5f

Please sign in to comment.