File tree 3 files changed +43
-1
lines changed
3 files changed +43
-1
lines changed Original file line number Diff line number Diff line change
1
+ import { useEffect } from "react" ;
2
+
3
+ export function useKbdShortcuts ( map : [ string , ( ) => void ] [ ] ) {
4
+ return useEffect ( ( ) => {
5
+ const documentListener = ( e : KeyboardEvent ) => {
6
+ const target = e . target as HTMLElement ;
7
+ if (
8
+ target . tagName === "INPUT" ||
9
+ target . tagName === "TEXTAREA" ||
10
+ target . isContentEditable
11
+ ) {
12
+ return ;
13
+ }
14
+
15
+ for ( const [ key , callback ] of map ) {
16
+ if ( e . key . toLowerCase ( ) === key . toLowerCase ( ) ) {
17
+ e . preventDefault ( ) ;
18
+ e . stopPropagation ( ) ;
19
+ callback ( ) ;
20
+ }
21
+ }
22
+ } ;
23
+
24
+ document . addEventListener ( "keydown" , documentListener ) ;
25
+
26
+ return ( ) => {
27
+ document . removeEventListener ( "keydown" , documentListener ) ;
28
+ } ;
29
+ } , [ map ] ) ;
30
+ }
Original file line number Diff line number Diff line change
1
+ export const hrefs = {
2
+ workspaces : {
3
+ create : "/workspace/create" ,
4
+ } ,
5
+ } ;
Original file line number Diff line number Diff line change @@ -19,6 +19,9 @@ import { useArchivedWorkspaces } from "@/features/workspace/hooks/use-archived-w
19
19
import { Workspace } from "@/api/generated" ;
20
20
import SvgFlipBackward from "@/components/icons/FlipBackward" ;
21
21
import { useRestoreWorkspaceButton } from "@/features/workspace/hooks/use-restore-workspace-button" ;
22
+ import { useKbdShortcuts } from "@/hooks/use-kbd-shortcuts" ;
23
+ import { useNavigate } from "react-router-dom" ;
24
+ import { hrefs } from "@/lib/hrefs" ;
22
25
23
26
function CellName ( {
24
27
name,
@@ -89,6 +92,10 @@ export function RouteWorkspaces() {
89
92
} ) ) ?? [ ] ) ,
90
93
] ;
91
94
95
+ const navigate = useNavigate ( ) ;
96
+
97
+ useKbdShortcuts ( [ [ "c" , ( ) => navigate ( hrefs . workspaces . create ) ] ] ) ;
98
+
92
99
return (
93
100
< >
94
101
< Breadcrumbs >
@@ -97,7 +104,7 @@ export function RouteWorkspaces() {
97
104
</ Breadcrumbs >
98
105
99
106
< WorkspaceHeading title = "Manage Workspaces" >
100
- < LinkButton href = "/workspace/ create" className = "w-fit gap-2" >
107
+ < LinkButton href = { hrefs . workspaces . create } className = "w-fit gap-2" >
101
108
< SquarePlus /> Create Workspace
102
109
</ LinkButton >
103
110
</ WorkspaceHeading >
You can’t perform that action at this time.
0 commit comments