From defb9567514bfb8fc471214be1cb895de0fba3e8 Mon Sep 17 00:00:00 2001 From: "santasri.pachhal" Date: Thu, 18 Jun 2026 11:41:25 +0530 Subject: [PATCH] refactor: pause video when click on logs --- src/components/video-player-section.tsx | 13 ++++++++++++- src/components/video/detection-logs.tsx | 11 +++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/components/video-player-section.tsx b/src/components/video-player-section.tsx index b0032ce..33440bc 100644 --- a/src/components/video-player-section.tsx +++ b/src/components/video-player-section.tsx @@ -44,6 +44,7 @@ export default function VideoPlayerSection({ projectId, }: VideoPlayerSectionProps) { const videoRef = useRef(null); + const shouldPauseAfterSeekRef = useRef(false); const sortedLogs = useMemo( () => [...(data.logs || [])].sort( @@ -66,9 +67,18 @@ export default function VideoPlayerSection({ const video = videoRef.current; if (!video) return; + shouldPauseAfterSeekRef.current = true; + video.pause(); video.currentTime = log.timestamp_seconds; setActiveLog(log); - void video.play(); + }; + + const handleSeeked = () => { + const video = videoRef.current; + if (!video || !shouldPauseAfterSeekRef.current) return; + + shouldPauseAfterSeekRef.current = false; + video.pause(); }; const handleTimeUpdate = () => { @@ -153,6 +163,7 @@ export default function VideoPlayerSection({ controls preload="metadata" onTimeUpdate={handleTimeUpdate} + onSeeked={handleSeeked} className="block w-full aspect-video" /> ) : ( diff --git a/src/components/video/detection-logs.tsx b/src/components/video/detection-logs.tsx index 0529ecd..9a8f62f 100644 --- a/src/components/video/detection-logs.tsx +++ b/src/components/video/detection-logs.tsx @@ -1,5 +1,6 @@ 'use client'; +import { useEffect, useRef } from 'react'; import { Activity, Film, MapPin } from 'lucide-react'; import { Badge } from '@/components/ui/badge'; import { ScrollArea } from '@/components/ui/scroll-area'; @@ -21,6 +22,15 @@ const formatVideoTime = (seconds: number) => { }; const DetectionLogs = ({ logs, activeLogId, onSeek }: DetectionLogsProps) => { + const activeLogRef = useRef(null); + + useEffect(() => { + activeLogRef.current?.scrollIntoView({ + block: 'nearest', + behavior: 'smooth', + }); + }, [activeLogId]); + return (
@@ -50,6 +60,7 @@ const DetectionLogs = ({ logs, activeLogId, onSeek }: DetectionLogsProps) => { return (