From be1ae20d9089e81cb84a8294be76fe680a24b60f Mon Sep 17 00:00:00 2001 From: Hyteq Date: Sun, 20 Jul 2025 11:00:22 +0300 Subject: format --- apps/web/src/hooks/use-keybinding-conflicts.ts | 96 +++++++++++++------------- 1 file changed, 48 insertions(+), 48 deletions(-) (limited to 'apps/web/src/hooks/use-keybinding-conflicts.ts') diff --git a/apps/web/src/hooks/use-keybinding-conflicts.ts b/apps/web/src/hooks/use-keybinding-conflicts.ts index cc5dd340..0720982e 100644 --- a/apps/web/src/hooks/use-keybinding-conflicts.ts +++ b/apps/web/src/hooks/use-keybinding-conflicts.ts @@ -5,55 +5,55 @@ import { useKeybindingsStore } from "@/stores/keybindings-store"; import { ActionWithOptionalArgs } from "@/constants/actions"; export interface KeybindingConflictInfo { - key: string; - actions: ActionWithOptionalArgs[]; - isConflict: boolean; + key: string; + actions: ActionWithOptionalArgs[]; + isConflict: boolean; } export const useKeybindingConflicts = () => { - const { keybindings } = useKeybindingsStore(); - - const conflicts = useMemo(() => { - const keyToActions: Record = {}; - const conflictList: KeybindingConflictInfo[] = []; - - // Group actions by key - Object.entries(keybindings).forEach(([key, action]) => { - if (!keyToActions[key]) { - keyToActions[key] = []; - } - keyToActions[key].push(action); - }); - - // Find conflicts - Object.entries(keyToActions).forEach(([key, actions]) => { - const uniqueActions = [...new Set(actions)]; - conflictList.push({ - key, - actions: uniqueActions, - isConflict: uniqueActions.length > 1, - }); - }); - - return conflictList.filter((item) => item.isConflict); - }, [keybindings]); - - const hasConflicts = conflicts.length > 0; - - const getConflictsForKey = (key: string): KeybindingConflictInfo | null => { - return conflicts.find((conflict) => conflict.key === key) || null; - }; - - const getConflictsForAction = ( - action: ActionWithOptionalArgs - ): KeybindingConflictInfo[] => { - return conflicts.filter((conflict) => conflict.actions.includes(action)); - }; - - return { - conflicts, - hasConflicts, - getConflictsForKey, - getConflictsForAction, - }; + const { keybindings } = useKeybindingsStore(); + + const conflicts = useMemo(() => { + const keyToActions: Record = {}; + const conflictList: KeybindingConflictInfo[] = []; + + // Group actions by key + Object.entries(keybindings).forEach(([key, action]) => { + if (!keyToActions[key]) { + keyToActions[key] = []; + } + keyToActions[key].push(action); + }); + + // Find conflicts + Object.entries(keyToActions).forEach(([key, actions]) => { + const uniqueActions = [...new Set(actions)]; + conflictList.push({ + key, + actions: uniqueActions, + isConflict: uniqueActions.length > 1, + }); + }); + + return conflictList.filter((item) => item.isConflict); + }, [keybindings]); + + const hasConflicts = conflicts.length > 0; + + const getConflictsForKey = (key: string): KeybindingConflictInfo | null => { + return conflicts.find((conflict) => conflict.key === key) || null; + }; + + const getConflictsForAction = ( + action: ActionWithOptionalArgs, + ): KeybindingConflictInfo[] => { + return conflicts.filter((conflict) => conflict.actions.includes(action)); + }; + + return { + conflicts, + hasConflicts, + getConflictsForKey, + getConflictsForAction, + }; }; -- cgit v1.3.1