🐛(frontend) fix shortcut handler type to properly handle promises

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.
This commit is contained in:
lebaudantoine
2025-08-22 14:06:21 +02:00
committed by aleb_the_flash
parent c1c2d0260d
commit bcf551a25c
3 changed files with 4 additions and 4 deletions

View File

@@ -87,7 +87,7 @@ export const ToggleDevice = <T extends ToggleSource>({
useRegisterKeyboardShortcut({ useRegisterKeyboardShortcut({
shortcut: deviceShortcut, shortcut: deviceShortcut,
handler: toggle, handler: async () => await toggle(),
isDisabled: cannotUseDevice, isDisabled: cannotUseDevice,
}) })
useLongPress({ useLongPress({

View File

@@ -10,7 +10,7 @@ export const useKeyboardShortcuts = () => {
useEffect(() => { useEffect(() => {
// This approach handles basic shortcuts but isn't comprehensive. // This approach handles basic shortcuts but isn't comprehensive.
// Issues might occur. First draft. // Issues might occur. First draft.
const onKeyDown = (e: KeyboardEvent) => { const onKeyDown = async (e: KeyboardEvent) => {
const { key, metaKey, ctrlKey } = e const { key, metaKey, ctrlKey } = e
if (!key) return if (!key) return
const shortcutKey = formatShortcutKey({ const shortcutKey = formatShortcutKey({
@@ -20,7 +20,7 @@ export const useKeyboardShortcuts = () => {
const shortcut = shortcutsSnap.shortcuts.get(shortcutKey) const shortcut = shortcutsSnap.shortcuts.get(shortcutKey)
if (!shortcut) return if (!shortcut) return
e.preventDefault() e.preventDefault()
shortcut() await shortcut()
} }
window.addEventListener('keydown', onKeyDown) window.addEventListener('keydown', onKeyDown)

View File

@@ -5,7 +5,7 @@ import { Shortcut } from '@/features/shortcuts/types'
export type useRegisterKeyboardShortcutProps = { export type useRegisterKeyboardShortcutProps = {
shortcut?: Shortcut shortcut?: Shortcut
handler: () => void handler: () => Promise<void | boolean | undefined> | void
isDisabled?: boolean isDisabled?: boolean
} }