Skip to content

Commit 0a0608b

Browse files
authored
⌨️ worxpace Add keyboard shortcuts (#68)
2 parents 93f4ad4 + 149828a commit 0a0608b

File tree

5 files changed

+38
-15
lines changed

5 files changed

+38
-15
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## Version `1.0.3`
44

5+
- `worxpace` Add keyboard shortcuts: settings panel, search palate, theme toggle
56
- `ui` Update components: `Tabs`, `DropdownMenu`, `Popover`
67
- `repo` Upgrade packages: `react`, `typescript`, `turbo`, `vitest`, `testing-library`, `eslint` plugins
78
- `repo` Setup test coverage

apps/worxpace/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"next": "^14.2.3",
3535
"react": "18.3.1",
3636
"react-dom": "18.3.1",
37+
"react-hotkeys-hook": "^4.5.0",
3738
"react-textarea-autosize": "^8.5.3",
3839
"sonner": "^1.3.1",
3940
"swr": "^2.2.5",

apps/worxpace/src/app/(platform)/(tools)/_components/sidebar.tsx

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
import {
77
forwardRef,
88
useCallback,
9-
useEffect,
109
type ForwardedRef,
1110
type MouseEventHandler,
1211
} from "react";
1312
import { useRouter } from "next/navigation";
1413
import { useAuth } from "@clerk/nextjs";
1514
// import { useAuth, useOrganizationList } from "@clerk/nextjs";
1615
import { ChevronsLeft } from "lucide-react";
16+
import { useHotkeys } from "react-hotkeys-hook";
1717

1818
import { Hint, CRUDItem as Item, useModal } from "@acme/ui/custom";
1919
import { cn } from "@acme/ui/lib";
@@ -22,7 +22,12 @@ import {
2222
WorkspaceSwitcher,
2323
type WorkspaceSwitcherProps,
2424
} from "@acme/ui/notion";
25-
import { Popover, PopoverContent, PopoverTrigger } from "@acme/ui/shadcn";
25+
import {
26+
Popover,
27+
PopoverContent,
28+
PopoverTrigger,
29+
useTheme,
30+
} from "@acme/ui/shadcn";
2631

2732
import { SearchCommand, SettingsModal } from "~/components/modal";
2833
import { theme } from "~/constants/theme";
@@ -89,18 +94,20 @@ export const Sidebar = forwardRef(function Sidebar(
8994
// eslint-disable-next-line react-hooks/exhaustive-deps
9095
[fetchSearchData],
9196
);
92-
93-
useEffect(() => {
94-
const down = (e: KeyboardEvent) => {
95-
if (e.key === "k" && (e.metaKey || e.ctrlKey)) {
96-
e.preventDefault();
97-
handleSearch();
98-
}
99-
};
100-
101-
addEventListener("keydown", down);
102-
return () => removeEventListener("keydown", down);
103-
}, [handleSearch]);
97+
/** Key events */
98+
const { theme: activeTheme, setTheme } = useTheme();
99+
const shortcutOptions = { preventDefault: true };
100+
useHotkeys(["meta+k", "shift+meta+k"], handleSearch, shortcutOptions);
101+
useHotkeys(
102+
["meta+comma", "shift+meta+comma"],
103+
handleSettings,
104+
shortcutOptions,
105+
);
106+
useHotkeys(
107+
"shift+meta+l",
108+
() => setTheme(activeTheme === "dark" ? "light" : "dark"),
109+
shortcutOptions,
110+
);
104111

105112
return (
106113
<aside

packages/ui/src/components/ui/theme.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,4 @@ function ThemeToggle() {
3939
);
4040
}
4141

42-
export { ThemeProvider, ThemeToggle };
42+
export { ThemeProvider, ThemeToggle, useTheme };

pnpm-lock.yaml

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)