From bcf551a25c1031163d597775449aa7f78ba18dd6 Mon Sep 17 00:00:00 2001 From: lebaudantoine Date: Fri, 22 Aug 2025 14:06:21 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B(frontend)=20fix=20shortcut=20handl?= =?UTF-8?q?er=20type=20to=20properly=20handle=20promises?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Correct TypeScript typing for shortcut handler that wasn't properly handling Promise return types. Ensures proper async operation handling and prevents potential runtime issues with promise-based shortcut actions. --- .../rooms/livekit/components/controls/Device/ToggleDevice.tsx | 2 +- src/frontend/src/features/shortcuts/useKeyboardShortcuts.ts | 4 ++-- .../src/features/shortcuts/useRegisterKeyboardShortcut.ts | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/frontend/src/features/rooms/livekit/components/controls/Device/ToggleDevice.tsx b/src/frontend/src/features/rooms/livekit/components/controls/Device/ToggleDevice.tsx index a567980e..b6770ca3 100644 --- a/src/frontend/src/features/rooms/livekit/components/controls/Device/ToggleDevice.tsx +++ b/src/frontend/src/features/rooms/livekit/components/controls/Device/ToggleDevice.tsx @@ -87,7 +87,7 @@ export const ToggleDevice = ({ useRegisterKeyboardShortcut({ shortcut: deviceShortcut, - handler: toggle, + handler: async () => await toggle(), isDisabled: cannotUseDevice, }) useLongPress({ diff --git a/src/frontend/src/features/shortcuts/useKeyboardShortcuts.ts b/src/frontend/src/features/shortcuts/useKeyboardShortcuts.ts index 09b471a6..d26fdf19 100644 --- a/src/frontend/src/features/shortcuts/useKeyboardShortcuts.ts +++ b/src/frontend/src/features/shortcuts/useKeyboardShortcuts.ts @@ -10,7 +10,7 @@ export const useKeyboardShortcuts = () => { useEffect(() => { // This approach handles basic shortcuts but isn't comprehensive. // Issues might occur. First draft. - const onKeyDown = (e: KeyboardEvent) => { + const onKeyDown = async (e: KeyboardEvent) => { const { key, metaKey, ctrlKey } = e if (!key) return const shortcutKey = formatShortcutKey({ @@ -20,7 +20,7 @@ export const useKeyboardShortcuts = () => { const shortcut = shortcutsSnap.shortcuts.get(shortcutKey) if (!shortcut) return e.preventDefault() - shortcut() + await shortcut() } window.addEventListener('keydown', onKeyDown) diff --git a/src/frontend/src/features/shortcuts/useRegisterKeyboardShortcut.ts b/src/frontend/src/features/shortcuts/useRegisterKeyboardShortcut.ts index 70b816f7..f39b1141 100644 --- a/src/frontend/src/features/shortcuts/useRegisterKeyboardShortcut.ts +++ b/src/frontend/src/features/shortcuts/useRegisterKeyboardShortcut.ts @@ -5,7 +5,7 @@ import { Shortcut } from '@/features/shortcuts/types' export type useRegisterKeyboardShortcutProps = { shortcut?: Shortcut - handler: () => void + handler: () => Promise | void isDisabled?: boolean }