From cfe4dc59b7cf86d161d3f17262d48b32da2df754 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 --- .../timeline/EventReviewTimeline.tsx | 4 ++- web/src/components/timeline/EventSegment.tsx | 14 +++++++++- web/src/views/events/DesktopEventView.tsx | 26 +++++++++++++------ 3 files changed, 34 insertions(+), 10 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 631dcd83a..7d60aeca0 100644 --- a/web/src/views/events/DesktopEventView.tsx +++ b/web/src/views/events/DesktopEventView.tsx @@ -5,6 +5,7 @@ import EventReviewTimeline from "@/components/timeline/EventReviewTimeline"; import ActivityIndicator from "@/components/ui/activity-indicator"; import { Button } from "@/components/ui/button"; 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"; @@ -41,6 +42,7 @@ export default function DesktopEventView({ const { data: config } = useSWR("config"); const [severity, setSeverity] = useState("alert"); const contentRef = useRef(null); + const segmentDuration = 60; // review paging @@ -76,6 +78,11 @@ export default function DesktopEventView({ }; }, [reviewPages]); + const { alignDateToTimeline } = useEventUtils( + reviewItems.all, + segmentDuration + ); + const currentItems = useMemo(() => { const current = reviewItems[severity]; @@ -91,8 +98,8 @@ export default function DesktopEventView({ return false; } - return contentRef.current.scrollHeight > contentRef.current.clientHeight - }, [contentRef.current?.scrollHeight]) + return contentRef.current.scrollHeight > contentRef.current.clientHeight; + }, [contentRef.current?.scrollHeight]); // review interaction @@ -244,10 +251,7 @@ export default function DesktopEventView({
-
+
{hasUpdate && (
@@ -276,7 +280,10 @@ export default function DesktopEventView({
)} -
+
{currentItems ? ( currentItems.map((value, segIdx) => { const lastRow = segIdx == reviewItems[severity].length - 1; @@ -294,6 +301,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 + } >