From 5b3fbecc0f5c8eeee587f9c11c133ea3010d1193 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Wed, 11 Mar 2026 19:24:41 +0200 Subject: [PATCH] feat(audio): introduce keyboard shortcuts --- .../src/widgets/type_widgets/file/Audio.tsx | 58 +++++++++++- .../widgets/type_widgets/file/MediaPlayer.css | 5 + .../src/widgets/type_widgets/file/Video.tsx | 92 ++++++++++--------- 3 files changed, 108 insertions(+), 47 deletions(-) diff --git a/apps/client/src/widgets/type_widgets/file/Audio.tsx b/apps/client/src/widgets/type_widgets/file/Audio.tsx index 3d48479977..81f343405b 100644 --- a/apps/client/src/widgets/type_widgets/file/Audio.tsx +++ b/apps/client/src/widgets/type_widgets/file/Audio.tsx @@ -1,4 +1,4 @@ -import { useRef, useState } from "preact/hooks"; +import { MutableRef, useCallback, useRef, useState } from "preact/hooks"; import FNote from "../../../entities/fnote"; import { t } from "../../../services/i18n"; @@ -7,10 +7,21 @@ import { LoopButton, PlaybackSpeed, PlayPauseButton, SeekBar, SkipButton, Volume export default function AudioPreview({ note }: { note: FNote }) { const [playing, setPlaying] = useState(false); + const wrapperRef = useRef(null); const audioRef = useRef(null); + const togglePlayback = useCallback(() => { + const audio = audioRef.current; + if (!audio) return; + if (audio.paused) { + audio.play(); + } else { + audio.pause(); + } + }, []); + const onKeyDown = useKeyboardShortcuts(audioRef, wrapperRef, togglePlayback); return ( -
+