diff --git a/web/src/components/timeline/EventSegment.tsx b/web/src/components/timeline/EventSegment.tsx index 5e2c40cba..8493bca40 100644 --- a/web/src/components/timeline/EventSegment.tsx +++ b/web/src/components/timeline/EventSegment.tsx @@ -19,6 +19,7 @@ type MinimapSegmentProps = { isLastSegmentInMinimap: boolean; alignedMinimapStartTime: number; alignedMinimapEndTime: number; + firstMinimapSegmentRef: React.MutableRefObject; }; type TickSegmentProps = { @@ -41,11 +42,15 @@ function MinimapBounds({ isLastSegmentInMinimap, alignedMinimapStartTime, alignedMinimapEndTime, + firstMinimapSegmentRef, }: MinimapSegmentProps) { return ( <> {isFirstSegmentInMinimap && ( -
+
{new Date(alignedMinimapStartTime * 1000).toLocaleTimeString([], { hour: "2-digit", minute: "2-digit", @@ -185,9 +190,12 @@ export function EventSegment({ // Check if the first segment is out of view const firstSegment = firstMinimapSegmentRef.current; if (firstSegment && showMinimap && isFirstSegmentInMinimap) { - firstSegment.scrollIntoView({ behavior: "smooth", block: "nearest" }); + firstSegment.scrollIntoView({ + behavior: "smooth", + block: "center", + }); } - }, [showMinimap, isFirstSegmentInMinimap, timestampSpread]); + }, [showMinimap, isFirstSegmentInMinimap, events, segmentDuration]); const segmentClasses = `flex flex-row ${ showMinimap @@ -222,6 +230,7 @@ export function EventSegment({ isLastSegmentInMinimap={isLastSegmentInMinimap} alignedMinimapStartTime={alignedMinimapStartTime} alignedMinimapEndTime={alignedMinimapEndTime} + firstMinimapSegmentRef={firstMinimapSegmentRef} />
{ - const start_time = Math.floor(Date.now() / 1000) - Math.random() * 60 * 60; + const start_time = + Math.floor(Date.now() / 1000) - 10800 - Math.random() * 60 * 60; const end_time = Math.floor(start_time + Math.random() * 60 * 10); const severities: ReviewSeverity[] = [ "significant_motion", @@ -123,6 +124,23 @@ function UIPlayground() { setMockEvents(initialEvents); }, []); + // Calculate minimap start and end times based on events + const minimapStartTime = useMemo(() => { + if (mockEvents && mockEvents.length > 0) { + return Math.min(...mockEvents.map((event) => event.start_time)); + } + return Math.floor(Date.now() / 1000); // Default to current time if no events + }, [events]); + + const minimapEndTime = useMemo(() => { + if (mockEvents && mockEvents.length > 0) { + return Math.max( + ...mockEvents.map((event) => event.end_time ?? event.start_time) + ); + } + return Math.floor(Date.now() / 1000); // Default to current time if no events + }, [events]); + const [zoomLevel, setZoomLevel] = useState(0); const [zoomSettings, setZoomSettings] = useState({ segmentDuration: 60, @@ -152,42 +170,42 @@ function UIPlayground() { return ( <> - UI Playground +
+
+ UI Playground - - Scrubber - -

- Shows the 10 most recent events within the last 4 hours -

+ + Scrubber + +

+ Shows the 10 most recent events within the last 4 hours +

- {!config && } + {!config && } - {config && ( -
- {events && events.length > 0 && ( - <> - - + {config && ( +
+ {events && events.length > 0 && ( + <> + + + )} +
)} -
- )} - {config && ( -
- {timeline && ( - <> - - + {config && ( +
+ {timeline && ( + <> + + + )} +
)} -
- )} -
-
Timeline @@ -229,23 +247,23 @@ function UIPlayground() {
-
- -
+
+
+
);