From 86880202f5f9c8dcec26bbac776941804aac52a3 Mon Sep 17 00:00:00 2001 From: Josh Hawkins <32435876+hawkeye217@users.noreply.github.com> Date: Mon, 26 Feb 2024 14:59:08 -0600 Subject: [PATCH] make event bars clickable --- .../components/timeline/EventReviewTimeline.tsx | 4 +++- web/src/components/timeline/EventSegment.tsx | 14 +++++++++++++- web/src/views/events/DesktopEventView.tsx | 17 +++++++++++++++-- 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/web/src/components/timeline/EventReviewTimeline.tsx b/web/src/components/timeline/EventReviewTimeline.tsx index d84b3ed75..d8c3a3250 100644 --- a/web/src/components/timeline/EventReviewTimeline.tsx +++ b/web/src/components/timeline/EventReviewTimeline.tsx @@ -102,7 +102,7 @@ export function EventReviewTimeline({ return ( ); }); @@ -122,6 +123,7 @@ export function EventReviewTimeline({ showMinimap, minimapStartTime, minimapEndTime, + events, ]); const segments = useMemo( diff --git a/web/src/components/timeline/EventSegment.tsx b/web/src/components/timeline/EventSegment.tsx index 7113e660e..f11f1ffca 100644 --- a/web/src/components/timeline/EventSegment.tsx +++ b/web/src/components/timeline/EventSegment.tsx @@ -1,7 +1,7 @@ import { useEventUtils } from "@/hooks/use-event-utils"; import { useSegmentUtils } from "@/hooks/use-segment-utils"; import { ReviewSegment, ReviewSeverity } from "@/types/review"; -import React, { useEffect, useMemo, useRef } from "react"; +import React, { RefObject, useEffect, useMemo, useRef } from "react"; type EventSegmentProps = { events: ReviewSegment[]; @@ -12,6 +12,7 @@ type EventSegmentProps = { minimapStartTime?: number; minimapEndTime?: number; severityType: ReviewSeverity; + contentRef: RefObject; }; type MinimapSegmentProps = { @@ -131,6 +132,7 @@ export function EventSegment({ minimapStartTime, minimapEndTime, severityType, + contentRef, }: EventSegmentProps) { const { getSeverity, @@ -269,6 +271,16 @@ export function EventSegment({ ${roundTop ? "rounded-tl-full rounded-tr-full" : ""} ${severityColors[severityValue]} `} + onClick={() => { + if (contentRef.current) { + const element = contentRef.current.querySelector( + `[data-segment-start="${segmentTime}"]` + ); + if (element instanceof HTMLElement) { + debounceScrollIntoView(element); + } + } + }} > )} diff --git a/web/src/views/events/DesktopEventView.tsx b/web/src/views/events/DesktopEventView.tsx index d6252315f..eaf336a95 100644 --- a/web/src/views/events/DesktopEventView.tsx +++ b/web/src/views/events/DesktopEventView.tsx @@ -4,6 +4,7 @@ import PreviewThumbnailPlayer from "@/components/player/PreviewThumbnailPlayer"; import EventReviewTimeline from "@/components/timeline/EventReviewTimeline"; import ActivityIndicator from "@/components/ui/activity-indicator"; import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group"; +import { useEventUtils } from "@/hooks/use-event-utils"; import { FrigateConfig } from "@/types/frigateConfig"; import { ReviewFilter, ReviewSegment, ReviewSeverity } from "@/types/review"; import { useCallback, useEffect, useMemo, useRef, useState } from "react"; @@ -43,6 +44,7 @@ export default function DesktopEventView({ }: DesktopEventViewProps) { const { data: config } = useSWR("config"); const contentRef = useRef(null); + const segmentDuration = 60; // review paging @@ -78,6 +80,11 @@ export default function DesktopEventView({ }; }, [reviewPages]); + const { alignDateToTimeline } = useEventUtils( + reviewItems.all, + segmentDuration + ); + const currentItems = useMemo(() => { const current = reviewItems[severity]; @@ -245,7 +252,10 @@ export default function DesktopEventView({ )} -
+
{currentItems ? ( currentItems.map((value, segIdx) => { const lastRow = segIdx == reviewItems[severity].length - 1; @@ -263,6 +273,9 @@ export default function DesktopEventView({ key={value.id} ref={lastRow ? lastReviewRef : minimapRef} data-start={value.start_time} + data-segment-start={ + alignDateToTimeline(value.start_time) - segmentDuration + } >