zoomable timeline on recording view

This commit is contained in:
Josh Hawkins 2024-11-29 20:37:12 -06:00
parent 5cf8df72fd
commit f09e9832a5

View File

@ -46,8 +46,7 @@ import { ASPECT_VERTICAL_LAYOUT, ASPECT_WIDE_LAYOUT } from "@/types/record";
import { useResizeObserver } from "@/hooks/resize-observer"; import { useResizeObserver } from "@/hooks/resize-observer";
import { cn } from "@/lib/utils"; import { cn } from "@/lib/utils";
import { useFullscreen } from "@/hooks/use-fullscreen"; import { useFullscreen } from "@/hooks/use-fullscreen";
import { useTimelineZoom } from "@/hooks/use-timeline-zoom";
const SEGMENT_DURATION = 30;
type RecordingViewProps = { type RecordingViewProps = {
startCamera: string; startCamera: string;
@ -657,12 +656,43 @@ function Timeline({
setScrubbing, setScrubbing,
setExportRange, setExportRange,
}: TimelineProps) { }: TimelineProps) {
// timeline interaction
const [zoomSettings, setZoomSettings] = useState({
segmentDuration: 30,
timestampSpread: 15,
});
const possibleZoomLevels = useMemo(
() => [
{ segmentDuration: 30, timestampSpread: 15 },
{ segmentDuration: 15, timestampSpread: 5 },
{ segmentDuration: 5, timestampSpread: 1 },
],
[],
);
const handleZoomChange = useCallback(
(newZoomLevel: number) => {
setZoomSettings(possibleZoomLevels[newZoomLevel]);
},
[possibleZoomLevels],
);
useTimelineZoom({
zoomSettings,
zoomLevels: possibleZoomLevels,
onZoomChange: handleZoomChange,
});
// motion data
const { data: motionData } = useSWR<MotionData[]>([ const { data: motionData } = useSWR<MotionData[]>([
"review/activity/motion", "review/activity/motion",
{ {
before: timeRange.before, before: timeRange.before,
after: timeRange.after, after: timeRange.after,
scale: SEGMENT_DURATION / 2, scale: Math.round(zoomSettings.segmentDuration / 2),
cameras: mainCamera, cameras: mainCamera,
}, },
]); ]);
@ -697,8 +727,8 @@ function Timeline({
{timelineType == "timeline" ? ( {timelineType == "timeline" ? (
motionData ? ( motionData ? (
<MotionReviewTimeline <MotionReviewTimeline
segmentDuration={30} segmentDuration={zoomSettings.segmentDuration}
timestampSpread={15} timestampSpread={zoomSettings.timestampSpread}
timelineStart={timeRange.before} timelineStart={timeRange.before}
timelineEnd={timeRange.after} timelineEnd={timeRange.after}
showHandlebar={exportRange == undefined} showHandlebar={exportRange == undefined}
@ -711,7 +741,6 @@ function Timeline({
setHandlebarTime={setCurrentTime} setHandlebarTime={setCurrentTime}
events={mainCameraReviewItems} events={mainCameraReviewItems}
motion_events={motionData ?? []} motion_events={motionData ?? []}
severityType="significant_motion"
contentRef={contentRef} contentRef={contentRef}
onHandlebarDraggingChange={(scrubbing) => setScrubbing(scrubbing)} onHandlebarDraggingChange={(scrubbing) => setScrubbing(scrubbing)}
/> />