From 5a7745f806edf4a386b8cfd079861f96c3b92baf Mon Sep 17 00:00:00 2001 From: Kha Nguyen Date: Thu, 24 Jul 2025 00:06:57 -0500 Subject: [PATCH] chore: remove unused variables and clean up code --- .../components/keyboard-shortcuts-help.tsx | 56 ++++++++----------- 1 file changed, 23 insertions(+), 33 deletions(-) diff --git a/apps/web/src/components/keyboard-shortcuts-help.tsx b/apps/web/src/components/keyboard-shortcuts-help.tsx index f6f2f222..65a73b90 100644 --- a/apps/web/src/components/keyboard-shortcuts-help.tsx +++ b/apps/web/src/components/keyboard-shortcuts-help.tsx @@ -1,6 +1,13 @@ "use client"; -import { useState, useEffect } from "react"; +import { Keyboard } from "lucide-react"; +import { useEffect, useState } from "react"; +import { toast } from "sonner"; +import { + type KeyboardShortcut, + useKeyboardShortcutsHelp, +} from "@/hooks/use-keyboard-shortcuts-help"; +import { useKeybindingsStore } from "@/stores/keybindings-store"; import { Button } from "./ui/button"; import { Dialog, @@ -11,13 +18,6 @@ import { DialogTitle, DialogTrigger, } from "./ui/dialog"; -import { Keyboard } from "lucide-react"; -import { - useKeyboardShortcutsHelp, - KeyboardShortcut, -} from "@/hooks/use-keyboard-shortcuts-help"; -import { useKeybindingsStore } from "@/stores/keybindings-store"; -import { toast } from "sonner"; const ShortcutItem = ({ shortcut, @@ -26,7 +26,7 @@ const ShortcutItem = ({ }: { shortcut: KeyboardShortcut; isRecording: boolean; - onStartRecording: (keyId: string, shortcut: KeyboardShortcut) => void; + onStartRecording: (shortcut: KeyboardShortcut) => void; }) => { // Filter out lowercase duplicates for display - if both "j" and "J" exist, only show "J" const displayKeys = shortcut.keys.filter((key: string) => { @@ -49,18 +49,15 @@ const ShortcutItem = ({
{displayKeys.map((key: string, index: number) => ( -
+
{key.split("+").map((keyPart: string, partIndex: number) => { const keyId = `${shortcut.id}-${index}-${partIndex}`; return ( onStartRecording(keyId, shortcut)} + onStartRecording={() => onStartRecording(shortcut)} > {keyPart} @@ -79,16 +76,10 @@ const ShortcutItem = ({ const EditableShortcutKey = ({ children, - keyId, - originalKey, - shortcut, isRecording, onStartRecording, }: { children: React.ReactNode; - keyId: string; - originalKey: string; - shortcut: KeyboardShortcut; isRecording: boolean; onStartRecording: () => void; }) => { @@ -99,7 +90,9 @@ const EditableShortcutKey = ({ }; return ( - {children} - + ); }; export const KeyboardShortcutsHelp = () => { const [open, setOpen] = useState(false); - const [recordingKey, setRecordingKey] = useState(null); const [recordingShortcut, setRecordingShortcut] = useState(null); @@ -129,6 +121,7 @@ export const KeyboardShortcutsHelp = () => { getKeybindingsForAction, setIsRecording, resetToDefaults, + isRecording, } = useKeybindingsStore(); // Get shortcuts from centralized hook @@ -137,7 +130,7 @@ export const KeyboardShortcutsHelp = () => { const categories = Array.from(new Set(shortcuts.map((s) => s.category))); useEffect(() => { - if (!recordingKey || !recordingShortcut) return; + if (!isRecording || !recordingShortcut) return; const handleKeyDown = (e: KeyboardEvent) => { e.preventDefault(); @@ -154,7 +147,6 @@ export const KeyboardShortcutsHelp = () => { toast.error( `Key "${keyString}" is already bound to "${conflict.existingAction}"`, ); - setRecordingKey(null); setRecordingShortcut(null); return; } @@ -167,13 +159,11 @@ export const KeyboardShortcutsHelp = () => { updateKeybinding(keyString, recordingShortcut.action); setIsRecording(false); - setRecordingKey(null); setRecordingShortcut(null); } }; const handleClickOutside = () => { - setRecordingKey(null); setRecordingShortcut(null); setIsRecording(false); }; @@ -186,17 +176,17 @@ export const KeyboardShortcutsHelp = () => { document.removeEventListener("click", handleClickOutside); }; }, [ - recordingKey, recordingShortcut, getKeybindingString, updateKeybinding, removeKeybinding, validateKeybinding, getKeybindingsForAction, + setIsRecording, + isRecording, ]); - const handleStartRecording = (keyId: string, shortcut: KeyboardShortcut) => { - setRecordingKey(keyId); + const handleStartRecording = (shortcut: KeyboardShortcut) => { setRecordingShortcut(shortcut); setIsRecording(true); }; @@ -230,9 +220,9 @@ export const KeyboardShortcutsHelp = () => {
{shortcuts .filter((shortcut) => shortcut.category === category) - .map((shortcut, index) => ( + .map((shortcut) => (