MCPcopy Create free account
hub / github.com/TanStack/hotkeys / App

Function App

examples/solid/createHotkeyRecorder/src/index.tsx:68–281  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

66]
67
68function App() {
69 const [shortcuts, setShortcuts] =
70 createSignal<Array<Shortcut>>(INITIAL_SHORTCUTS)
71
72 // Track which shortcut is being edited (recording + name/description editing)
73 const [editingId, setEditingId] = createSignal<string | null>(null)
74 // Draft name/description while editing
75 const [draftName, setDraftName] = createSignal('')
76 const [draftDescription, setDraftDescription] = createSignal('')
77
78 const recorder = createHotkeyRecorder({
79 onRecord: (hotkey: Hotkey) => {
80 const id = editingId()
81 if (id) {
82 setShortcuts((prev) =>
83 prev.map((s) =>
84 s.id === id
85 ? {
86 ...s,
87 hotkey,
88 name: draftName(),
89 description: draftDescription(),
90 }
91 : s,
92 ),
93 )
94 setEditingId(null)
95 }
96 },
97 onCancel: () => {
98 const id = editingId()
99 if (id) {
100 setShortcuts((prev) => {
101 const shortcut = prev.find((s) => s.id === id)
102 if (shortcut && shortcut.hotkey === '') {
103 return prev.filter((s) => s.id !== id)
104 }
105 return prev
106 })
107 }
108 setEditingId(null)
109 },
110 onClear: () => {
111 const id = editingId()
112 if (id) {
113 setShortcuts((prev) =>
114 prev.map((s) =>
115 s.id === id
116 ? {
117 ...s,
118 hotkey: '' as Hotkey | '',
119 name: draftName(),
120 description: draftDescription(),
121 }
122 : s,
123 ),
124 )
125 setEditingId(null)

Callers

nothing calls this directly

Calls 5

createHotkeyRecorderFunction · 0.90
createHotkeysFunction · 0.90
handleEditFunction · 0.70
handleDeleteFunction · 0.70
isRecordingMethod · 0.45

Tested by

no test coverage detected