-
Notifications
You must be signed in to change notification settings - Fork 969
Expand file tree
/
Copy pathKeybindHandler.tsx
More file actions
153 lines (145 loc) · 3.66 KB
/
KeybindHandler.tsx
File metadata and controls
153 lines (145 loc) · 3.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
import React, { useContext } from "react"
import { GlobalHotKeys, type KeyMap } from "react-hotkeys"
import { ReactotronContext, StateContext } from "reactotron-core-ui"
import LayoutContext from "./contexts/Layout"
const keyMap = {
// Application wide
ToggleSidebar: {
name: "Toggle Sidebar",
group: "Application",
sequences: ["command+shift+s", "ctrl+shift+s"],
action: "keyup",
},
// Tab Navigation
OpenHomeTab: {
name: "Home tab",
group: "Navigation",
sequences: ["command+1", "ctrl+1"],
action: "keyup",
},
OpenTimelineTab: {
name: "Timeline tab",
group: "Navigation",
sequences: ["command+2", "ctrl+2"],
action: "keyup",
},
OpenStateTab: {
name: "State tab",
group: "Navigation",
sequences: ["command+3", "ctrl+3"],
action: "keyup",
},
OpenReactNativeTab: {
name: "React Native tab",
group: "Navigation",
sequences: ["command+4", "ctrl+4"],
action: "keyup",
},
OpenCustomCommandsTab: {
name: "Custom Commands tab",
group: "Navigation",
sequences: ["command+5", "ctrl+5"],
action: "keyup",
},
OpenPreferencesTab: {
name: "Preferences tab",
group: "Navigation",
sequences: ["command+,", "ctrl+,"],
action: "keyup",
},
OpenHelpTab: {
name: "Help tab",
group: "Navigation",
sequences: ["command+?", "ctrl+?"],
action: "keyup",
},
// Timeline
ClearTimeline: {
name: "Clear Timeline",
group: "Timeline",
sequences: ["command+k", "ctrl+k"],
action: "keyup",
},
// Modals
// TODO: What keybinding should this be set to?
// OpenFindKeysValuesModal: {
// name: "Find keys or values",
// group: "State",
// sequences: ["command+k", "ctrl+k"],
// action: "keyup" ,
// },
OpenSubscriptionModal: {
name: "Open Subscription modal",
group: "State",
sequences: ["command+n", "ctrl+n"],
action: "keyup",
},
OpenDispatchModal: {
name: "Open Dispatch modal",
group: "State",
sequences: ["command+d", "ctrl+d"],
action: "keyup",
},
TakeSnapshot: {
name: "Take snapshot",
group: "State",
sequences: ["command+s", "ctrl+s"],
action: "keyup",
},
} satisfies KeyMap
type ActionName = keyof typeof keyMap
function KeybindHandler({ children }) {
const { toggleSideBar } = useContext(LayoutContext)
const { openDispatchModal, openSubscriptionModal, clearCommands } = useContext(ReactotronContext)
const { createSnapshot } = useContext(StateContext)
const handlers = {
// Tab Navigation
OpenHomeTab: () => {
window.location.hash = "/home"
},
OpenTimelineTab: () => {
window.location.hash = "/"
},
OpenStateTab: () => {
window.location.hash = "/state/subscriptions"
},
OpenReactNativeTab: () => {
window.location.hash = "/native/overlay"
},
OpenCustomCommandsTab: () => {
window.location.hash = "/customCommands"
},
OpenPreferencesTab: () => {
window.location.hash = "/preferences"
},
OpenHelpTab: () => {
window.location.hash = "/help"
},
// Modals
// OpenFindKeysValuesModal: () => {
// throw new Error("Implement Me!")
// },
OpenSubscriptionModal: () => {
openSubscriptionModal()
},
OpenDispatchModal: () => {
openDispatchModal("")
},
TakeSnapshot: () => {
createSnapshot()
},
// Miscellaneous
ToggleSidebar: () => {
toggleSideBar()
},
ClearTimeline: () => {
clearCommands()
},
} satisfies Record<ActionName, (keyEvent: KeyboardEvent) => void>
return (
<GlobalHotKeys keyMap={keyMap} handlers={handlers}>
{children}
</GlobalHotKeys>
)
}
export default KeybindHandler