-
-
Notifications
You must be signed in to change notification settings - Fork 126
Expand file tree
/
Copy pathOnboardingShortcutInput.tsx
More file actions
64 lines (59 loc) Β· 1.89 KB
/
Copy pathOnboardingShortcutInput.tsx
File metadata and controls
64 lines (59 loc) Β· 1.89 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
import { useState, useEffect } from "react";
import { Label } from "@/components/ui/label";
import { ShortcutInput } from "@/components/shortcut-input";
import { api } from "@/trpc/react";
import { toast } from "sonner";
/**
* Push to Talk shortcut input for onboarding
* Wraps ShortcutInput with label and handles data fetching/saving
*/
export function OnboardingShortcutInput() {
const [pushToTalkShortcut, setPushToTalkShortcut] = useState<number[]>([]);
const [isRecording, setIsRecording] = useState(false);
const utils = api.useUtils();
const shortcutsQuery = api.settings.getShortcuts.useQuery();
const setShortcutMutation = api.settings.setShortcut.useMutation({
onSuccess: () => {
utils.settings.getShortcuts.invalidate();
},
onError: (error) => {
toast.error(error.message);
// Revert to saved value
utils.settings.getShortcuts.invalidate();
},
});
// Load current shortcut
useEffect(() => {
if (shortcutsQuery.data) {
setPushToTalkShortcut(shortcutsQuery.data.pushToTalk);
}
}, [shortcutsQuery.data]);
const handleShortcutChange = (shortcut: number[]) => {
setPushToTalkShortcut(shortcut);
setShortcutMutation.mutate({
type: "pushToTalk",
shortcut: shortcut,
});
};
return (
<div className="flex items-center justify-between">
<div>
<Label className="text-base font-semibold text-foreground">
Push to talk
</Label>
<p className="text-xs text-muted-foreground mt-1">
Hold to dictate while key is pressed
</p>
</div>
<div className="min-w-[200px] flex justify-end">
<ShortcutInput
value={pushToTalkShortcut}
onChange={handleShortcutChange}
isRecordingShortcut={isRecording}
onRecordingShortcutChange={setIsRecording}
shortcutId="pushToTalk"
/>
</div>
</div>
);
}