import DynamicVideoPlayer, { DynamicVideoController, } from "@/components/player/DynamicVideoPlayer"; import EventReviewTimeline from "@/components/timeline/EventReviewTimeline"; import { Button } from "@/components/ui/button"; import { ReviewSegment } from "@/types/review"; import { getChunkedTimeRange } from "@/utils/timelineUtil"; import { useEffect, useMemo, useRef, useState } from "react"; import { IoMdArrowRoundBack } from "react-icons/io"; import { useNavigate } from "react-router-dom"; type DesktopRecordingViewProps = { selectedReview: ReviewSegment; reviewItems: ReviewSegment[]; relevantPreviews?: Preview[]; }; export default function DesktopRecordingView({ selectedReview, reviewItems, relevantPreviews, }: DesktopRecordingViewProps) { const navigate = useNavigate(); const contentRef = useRef(null); // controller state const [playerReady, setPlayerReady] = useState(false); const controllerRef = useRef(undefined); // timeline time const timeRange = useMemo( () => getChunkedTimeRange(selectedReview.start_time), [] ); const [selectedRangeIdx, setSelectedRangeIdx] = useState( timeRange.ranges.findIndex((chunk) => { return ( chunk.start <= selectedReview.start_time && chunk.end >= selectedReview.start_time ); }) ); // move to next clip useEffect(() => { if (!controllerRef.current) { return; } controllerRef.current.onClipChangedEvent((dir) => { if (dir == "forward" && selectedRangeIdx < timeRange.ranges.length - 1) { setSelectedRangeIdx(selectedRangeIdx + 1); } else if (selectedRangeIdx > 0) { setSelectedRangeIdx(selectedRangeIdx - 1); } }); }, [playerReady, selectedRangeIdx]); // scrubbing and timeline state const [scrubbing, setScrubbing] = useState(false); const [currentTime, setCurrentTime] = useState( selectedReview?.start_time || Date.now() / 1000 ); useEffect(() => { if (scrubbing) { controllerRef.current?.scrubToTimestamp(currentTime); } }, [currentTime, scrubbing]); useEffect(() => { if (!scrubbing) { controllerRef.current?.seekToTimestamp(currentTime, true); } }, [scrubbing]); return (
{ controllerRef.current = controller; setPlayerReady(true); controllerRef.current.onPlayerTimeUpdate((timestamp: number) => { setCurrentTime(timestamp); }); controllerRef.current?.seekToTimestamp( selectedReview.start_time, true ); }} />
setScrubbing(scrubbing)} />
); }