refactor: pause video when click on logs

This commit is contained in:
2026-06-18 11:41:25 +05:30
parent c6894bfea0
commit defb956751
2 changed files with 23 additions and 1 deletions

View File

@@ -44,6 +44,7 @@ export default function VideoPlayerSection({
projectId, projectId,
}: VideoPlayerSectionProps) { }: VideoPlayerSectionProps) {
const videoRef = useRef<HTMLVideoElement>(null); const videoRef = useRef<HTMLVideoElement>(null);
const shouldPauseAfterSeekRef = useRef(false);
const sortedLogs = useMemo( const sortedLogs = useMemo(
() => () =>
[...(data.logs || [])].sort( [...(data.logs || [])].sort(
@@ -66,9 +67,18 @@ export default function VideoPlayerSection({
const video = videoRef.current; const video = videoRef.current;
if (!video) return; if (!video) return;
shouldPauseAfterSeekRef.current = true;
video.pause();
video.currentTime = log.timestamp_seconds; video.currentTime = log.timestamp_seconds;
setActiveLog(log); setActiveLog(log);
void video.play(); };
const handleSeeked = () => {
const video = videoRef.current;
if (!video || !shouldPauseAfterSeekRef.current) return;
shouldPauseAfterSeekRef.current = false;
video.pause();
}; };
const handleTimeUpdate = () => { const handleTimeUpdate = () => {
@@ -153,6 +163,7 @@ export default function VideoPlayerSection({
controls controls
preload="metadata" preload="metadata"
onTimeUpdate={handleTimeUpdate} onTimeUpdate={handleTimeUpdate}
onSeeked={handleSeeked}
className="block w-full aspect-video" className="block w-full aspect-video"
/> />
) : ( ) : (

View File

@@ -1,5 +1,6 @@
'use client'; 'use client';
import { useEffect, useRef } from 'react';
import { Activity, Film, MapPin } from 'lucide-react'; import { Activity, Film, MapPin } from 'lucide-react';
import { Badge } from '@/components/ui/badge'; import { Badge } from '@/components/ui/badge';
import { ScrollArea } from '@/components/ui/scroll-area'; import { ScrollArea } from '@/components/ui/scroll-area';
@@ -21,6 +22,15 @@ const formatVideoTime = (seconds: number) => {
}; };
const DetectionLogs = ({ logs, activeLogId, onSeek }: DetectionLogsProps) => { const DetectionLogs = ({ logs, activeLogId, onSeek }: DetectionLogsProps) => {
const activeLogRef = useRef<HTMLButtonElement | null>(null);
useEffect(() => {
activeLogRef.current?.scrollIntoView({
block: 'nearest',
behavior: 'smooth',
});
}, [activeLogId]);
return ( return (
<div className="space-y-4"> <div className="space-y-4">
<div className="flex items-center justify-between"> <div className="flex items-center justify-between">
@@ -50,6 +60,7 @@ const DetectionLogs = ({ logs, activeLogId, onSeek }: DetectionLogsProps) => {
return ( return (
<button <button
key={`${log.id}-${log.frame}`} key={`${log.id}-${log.frame}`}
ref={isActive ? activeLogRef : null}
type="button" type="button"
onClick={() => onSeek(log)} onClick={() => onSeek(log)}
className={cn( className={cn(