From 35996733a9e26e5a3296a3c55ba40232ef0c3ee1 Mon Sep 17 00:00:00 2001 From: Nicolas Mowen Date: Tue, 26 Mar 2024 09:30:07 -0600 Subject: [PATCH] Move timeline to separate component --- web/src/views/events/RecordingView.tsx | 144 ++++++++++++++++++------- 1 file changed, 107 insertions(+), 37 deletions(-) diff --git a/web/src/views/events/RecordingView.tsx b/web/src/views/events/RecordingView.tsx index a18660aea..8d84d6fa2 100644 --- a/web/src/views/events/RecordingView.tsx +++ b/web/src/views/events/RecordingView.tsx @@ -8,6 +8,7 @@ import DynamicVideoPlayer from "@/components/player/dynamic/DynamicVideoPlayer"; import MotionReviewTimeline from "@/components/timeline/MotionReviewTimeline"; import { Button } from "@/components/ui/button"; import { Drawer, DrawerContent, DrawerTrigger } from "@/components/ui/drawer"; +import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group"; import { FrigateConfig } from "@/types/frigateConfig"; import { Preview } from "@/types/preview"; import { @@ -17,7 +18,14 @@ import { ReviewSummary, } from "@/types/review"; import { getChunkedTimeDay } from "@/utils/timelineUtil"; -import { useCallback, useEffect, useMemo, useRef, useState } from "react"; +import { + MutableRefObject, + useCallback, + useEffect, + useMemo, + useRef, + useState, +} from "react"; import { isDesktop, isMobile } from "react-device-detect"; import { FaCircle, FaVideo } from "react-icons/fa"; import { IoMdArrowRoundBack } from "react-icons/io"; @@ -25,6 +33,7 @@ import { useNavigate } from "react-router-dom"; import useSWR from "swr"; const SEGMENT_DURATION = 30; +type TimelineType = "timeline" | "events"; type RecordingViewProps = { startCamera: string; @@ -63,7 +72,9 @@ export function RecordingView({ [reviewItems, mainCamera], ); - // timeline time + // timeline + + const [timelineType, setTimelineType] = useState("timeline"); const timeRange = useMemo(() => getChunkedTimeDay(startTime), [startTime]); const [selectedRangeIdx, setSelectedRangeIdx] = useState( @@ -164,16 +175,6 @@ export function RecordingView({ // motion timeline data - const { data: motionData } = useSWR([ - "review/activity/motion", - { - before: timeRange.end, - after: timeRange.start, - scale: SEGMENT_DURATION / 2, - cameras: mainCamera, - }, - ]); - const mainCameraAspect = useMemo(() => { if (!config) { return "normal"; @@ -209,7 +210,7 @@ export function RecordingView({ Back -
+
{isMobile && ( @@ -247,6 +248,30 @@ export function RecordingView({ motionOnly={false} setMotionOnly={() => {}} /> + + value ? setTimelineType(value) : null + } // don't allow the severity to be unselected + > + +
Timeline
+
+ +
Events
+
+
@@ -317,31 +342,76 @@ export function RecordingView({ )} - -
- setScrubbing(scrubbing)} - /> -
+ ); } + +type TimelineProps = { + contentRef: MutableRefObject; + mainCamera: string; + timelineType: TimelineType; + timeRange: { start: number; end: number }; + mainCameraReviewItems: ReviewSegment[]; + currentTime: number; + setCurrentTime: React.Dispatch>; + setScrubbing: React.Dispatch>; +}; +function Timeline({ + contentRef, + mainCamera, + timelineType, + timeRange, + mainCameraReviewItems, + currentTime, + setCurrentTime, + setScrubbing, +}: TimelineProps) { + const { data: motionData } = useSWR([ + "review/activity/motion", + { + before: timeRange.end, + after: timeRange.start, + scale: SEGMENT_DURATION / 2, + cameras: mainCamera, + }, + ]); + + if (timelineType == "timeline") { + return ( +
+ setScrubbing(scrubbing)} + /> +
+ ); + } +}