From 4303f3687e580fc403bf4b459b5c159564ca95ed Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Tue, 10 Mar 2026 19:12:52 +0200 Subject: [PATCH] refactor(video_player): extract seek bar & volume control --- .../src/widgets/type_widgets/file/Video.tsx | 117 ++++++++++-------- 1 file changed, 66 insertions(+), 51 deletions(-) diff --git a/apps/client/src/widgets/type_widgets/file/Video.tsx b/apps/client/src/widgets/type_widgets/file/Video.tsx index dfdb33adac..3a7e87ef6a 100644 --- a/apps/client/src/widgets/type_widgets/file/Video.tsx +++ b/apps/client/src/widgets/type_widgets/file/Video.tsx @@ -1,5 +1,6 @@ import "./Video.css"; +import { RefObject } from "preact"; import { useEffect, useRef, useState } from "preact/hooks"; import FNote from "../../../entities/fnote"; @@ -15,10 +16,6 @@ function formatTime(seconds: number): string { export default function VideoPreview({ note }: { note: FNote }) { const videoRef = useRef(null); const [playing, setPlaying] = useState(false); - const [currentTime, setCurrentTime] = useState(0); - const [duration, setDuration] = useState(0); - const [volume, setVolume] = useState(1); - const [muted, setMuted] = useState(false); const togglePlayback = () => { const video = videoRef.current; @@ -31,6 +28,36 @@ export default function VideoPreview({ note }: { note: FNote }) { } }; + return ( +
+
+ ); +} + +function SeekBar({ videoRef }: { videoRef: RefObject }) { + const [currentTime, setCurrentTime] = useState(0); + const [duration, setDuration] = useState(0); + useEffect(() => { const video = videoRef.current; if (!video) return; @@ -52,6 +79,27 @@ export default function VideoPreview({ note }: { note: FNote }) { video.currentTime = parseFloat((e.target as HTMLInputElement).value); }; + return ( +
+ {formatTime(currentTime)} + + -{formatTime(Math.max(0, duration - currentTime))} +
+ ); +} + +function VolumeControl({ videoRef }: { videoRef: RefObject }) { + const [volume, setVolume] = useState(1); + const [muted, setMuted] = useState(false); + const onVolumeChange = (e: Event) => { const video = videoRef.current; if (!video) return; @@ -72,54 +120,21 @@ export default function VideoPreview({ note }: { note: FNote }) { }; return ( -
-