hover thumbnails

This commit is contained in:
Josh Hawkins 2024-02-27 09:51:41 -06:00
parent dfd7f994f9
commit ae32e3a287
3 changed files with 121 additions and 65 deletions

View File

@ -10,6 +10,7 @@ import {
import EventSegment from "./EventSegment"; import EventSegment from "./EventSegment";
import { useEventUtils } from "@/hooks/use-event-utils"; import { useEventUtils } from "@/hooks/use-event-utils";
import { ReviewSegment, ReviewSeverity } from "@/types/review"; import { ReviewSegment, ReviewSeverity } from "@/types/review";
import { TooltipProvider } from "../ui/tooltip";
export type EventReviewTimelineProps = { export type EventReviewTimelineProps = {
segmentDuration: number; segmentDuration: number;
@ -212,6 +213,7 @@ export function EventReviewTimeline({
]); ]);
return ( return (
<TooltipProvider skipDelayDuration={3000}>
<div <div
ref={timelineRef} ref={timelineRef}
className={`relative w-[120px] md:w-[100px] h-full overflow-y-scroll no-scrollbar bg-secondary ${ className={`relative w-[120px] md:w-[100px] h-full overflow-y-scroll no-scrollbar bg-secondary ${
@ -220,7 +222,10 @@ export function EventReviewTimeline({
> >
<div className="flex flex-col">{segments}</div> <div className="flex flex-col">{segments}</div>
{showHandlebar && ( {showHandlebar && (
<div className={`absolute left-0 top-0 z-20 w-full `} role="scrollbar"> <div
className={`absolute left-0 top-0 z-20 w-full `}
role="scrollbar"
>
<div className={`flex items-center justify-center `}> <div className={`flex items-center justify-center `}>
<div <div
ref={scrollTimeRef} ref={scrollTimeRef}
@ -245,6 +250,7 @@ export function EventReviewTimeline({
</div> </div>
)} )}
</div> </div>
</TooltipProvider>
); );
} }

View File

@ -1,3 +1,4 @@
import { useApiHost } from "@/api";
import { useEventUtils } from "@/hooks/use-event-utils"; import { useEventUtils } from "@/hooks/use-event-utils";
import { useSegmentUtils } from "@/hooks/use-segment-utils"; import { useSegmentUtils } from "@/hooks/use-segment-utils";
import { ReviewSegment, ReviewSeverity } from "@/types/review"; import { ReviewSegment, ReviewSeverity } from "@/types/review";
@ -8,6 +9,8 @@ import React, {
useMemo, useMemo,
useRef, useRef,
} from "react"; } from "react";
import { Tooltip, TooltipContent } from "../ui/tooltip";
import { TooltipTrigger } from "@radix-ui/react-tooltip";
type EventSegmentProps = { type EventSegmentProps = {
events: ReviewSegment[]; events: ReviewSegment[];
@ -146,6 +149,7 @@ export function EventSegment({
displaySeverityType, displaySeverityType,
shouldShowRoundedCorners, shouldShowRoundedCorners,
getEventStart, getEventStart,
getEventThumbnail,
} = useSegmentUtils(segmentDuration, events, severityType); } = useSegmentUtils(segmentDuration, events, severityType);
const { alignDateToTimeline } = useEventUtils(events, segmentDuration); const { alignDateToTimeline } = useEventUtils(events, segmentDuration);
@ -154,22 +158,35 @@ export function EventSegment({
() => getSeverity(segmentTime, displaySeverityType), () => getSeverity(segmentTime, displaySeverityType),
[getSeverity, segmentTime] [getSeverity, segmentTime]
); );
const reviewed = useMemo( const reviewed = useMemo(
() => getReviewed(segmentTime), () => getReviewed(segmentTime),
[getReviewed, segmentTime] [getReviewed, segmentTime]
); );
const { roundTop, roundBottom } = useMemo(
const {
roundTopPrimary,
roundBottomPrimary,
roundTopSecondary,
roundBottomSecondary,
} = useMemo(
() => shouldShowRoundedCorners(segmentTime), () => shouldShowRoundedCorners(segmentTime),
[shouldShowRoundedCorners, segmentTime] [shouldShowRoundedCorners, segmentTime]
); );
const startTimestamp = useMemo(() => { const startTimestamp = useMemo(() => {
const eventStart = getEventStart(segmentTime); const eventStart = getEventStart(segmentTime);
if (eventStart) { if (eventStart) {
console.log("event start: " + new Date(eventStart * 1000));
return alignDateToTimeline(eventStart); return alignDateToTimeline(eventStart);
} }
}, [getEventStart, segmentTime]); }, [getEventStart, segmentTime]);
const apiHost = useApiHost();
const eventThumbnail = useMemo(() => {
return getEventThumbnail(segmentTime);
}, [getEventThumbnail, segmentTime]);
const timestamp = useMemo(() => new Date(segmentTime * 1000), [segmentTime]); const timestamp = useMemo(() => new Date(segmentTime * 1000), [segmentTime]);
const segmentKey = useMemo(() => segmentTime, [segmentTime]); const segmentKey = useMemo(() => segmentTime, [segmentTime]);
@ -247,7 +264,6 @@ export function EventSegment({
const segmentClick = useCallback(() => { const segmentClick = useCallback(() => {
if (contentRef.current && startTimestamp) { if (contentRef.current && startTimestamp) {
console.log(new Date(startTimestamp * 1000));
const element = contentRef.current.querySelector( const element = contentRef.current.querySelector(
`[data-segment-start="${startTimestamp - segmentDuration}"]` `[data-segment-start="${startTimestamp - segmentDuration}"]`
); );
@ -297,23 +313,31 @@ export function EventSegment({
{severity.map((severityValue, index) => ( {severity.map((severityValue, index) => (
<React.Fragment key={index}> <React.Fragment key={index}>
{severityValue === displaySeverityType && ( {severityValue === displaySeverityType && (
<Tooltip delayDuration={300}>
<div <div
className="mr-3 w-[8px] h-2 flex justify-left items-end" className="mr-3 w-[8px] h-2 flex justify-left items-end"
data-severity={severityValue} data-severity={severityValue}
> >
<TooltipTrigger asChild>
<div <div
key={`${segmentKey}_${index}_primary_data`} key={`${segmentKey}_${index}_primary_data`}
className={` className={`
w-full h-2 bg-gradient-to-r w-full h-2 bg-gradient-to-r
${roundBottom ? "rounded-bl-full rounded-br-full" : ""} ${roundBottomPrimary ? "rounded-bl-full rounded-br-full" : ""}
${roundTop ? "rounded-tl-full rounded-tr-full" : ""} ${roundTopPrimary ? "rounded-tl-full rounded-tr-full" : ""}
${severityColors[severityValue]} ${severityColors[severityValue]}
`} `}
onClick={() => { onClick={segmentClick}
segmentClick();
}}
></div> ></div>
</TooltipTrigger>
<TooltipContent className="rounded-2xl" side="left">
<img
className="rounded-lg"
src={`${apiHost}${eventThumbnail.replace("/media/frigate/", "")}`}
/>
</TooltipContent>
</div> </div>
</Tooltip>
)} )}
{severityValue !== displaySeverityType && ( {severityValue !== displaySeverityType && (
@ -322,8 +346,8 @@ export function EventSegment({
key={`${segmentKey}_${index}_secondary_data`} key={`${segmentKey}_${index}_secondary_data`}
className={` className={`
w-1 h-2 bg-gradient-to-r w-1 h-2 bg-gradient-to-r
${roundBottom ? "rounded-bl-full rounded-br-full" : ""} ${roundBottomSecondary ? "rounded-bl-full rounded-br-full" : ""}
${roundTop ? "rounded-tl-full rounded-tr-full" : ""} ${roundTopSecondary ? "rounded-tl-full rounded-tr-full" : ""}
${severityColors[severityValue]} ${severityColors[severityValue]}
`} `}
></div> ></div>

View File

@ -84,7 +84,14 @@ export const useSegmentUtils = (
); );
const shouldShowRoundedCorners = useCallback( const shouldShowRoundedCorners = useCallback(
(segmentTime: number): { roundTop: boolean; roundBottom: boolean } => { (
segmentTime: number
): {
roundTopPrimary: boolean;
roundBottomPrimary: boolean;
roundTopSecondary: boolean;
roundBottomSecondary: boolean;
} => {
const prevSegmentTime = segmentTime - segmentDuration; const prevSegmentTime = segmentTime - segmentDuration;
const nextSegmentTime = segmentTime + segmentDuration; const nextSegmentTime = segmentTime + segmentDuration;
@ -134,23 +141,26 @@ export const useSegmentUtils = (
); );
}); });
let roundTop = false; let roundTopPrimary = false;
let roundBottom = false; let roundBottomPrimary = false;
let roundTopSecondary = false;
let roundBottomSecondary = false;
if (hasOverlappingSeverityEvent) { if (hasOverlappingSeverityEvent) {
roundBottom = !hasPrevSeverityEvent; roundBottomPrimary = !hasPrevSeverityEvent;
roundTop = !hasNextSeverityEvent; roundTopPrimary = !hasNextSeverityEvent;
} else if (hasOverlappingOtherEvent) { }
roundBottom = !hasPrevOtherEvent;
roundTop = !hasNextOtherEvent; if (hasOverlappingOtherEvent) {
} else { roundBottomSecondary = !hasPrevOtherEvent;
roundTop = !hasNextSeverityEvent || !hasNextOtherEvent; roundTopSecondary = !hasNextOtherEvent;
roundBottom = !hasPrevSeverityEvent || !hasPrevOtherEvent;
} }
return { return {
roundTop, roundTopPrimary,
roundBottom, roundBottomPrimary,
roundTopSecondary,
roundBottomSecondary,
}; };
}, },
[events, getSegmentStart, getSegmentEnd, segmentDuration, severityType] [events, getSegmentStart, getSegmentEnd, segmentDuration, severityType]
@ -171,6 +181,21 @@ export const useSegmentUtils = (
[events, getSegmentStart, getSegmentEnd, severityType] [events, getSegmentStart, getSegmentEnd, severityType]
); );
const getEventThumbnail = useCallback(
(time: number): string => {
const matchingEvent = events.find((event) => {
return (
time >= getSegmentStart(event.start_time) &&
time < getSegmentEnd(event.end_time) &&
event.severity == severityType
);
});
return matchingEvent?.thumb_path ?? "";
},
[events, getSegmentStart, getSegmentEnd, severityType]
);
return { return {
getSegmentStart, getSegmentStart,
getSegmentEnd, getSegmentEnd,
@ -179,5 +204,6 @@ export const useSegmentUtils = (
getReviewed, getReviewed,
shouldShowRoundedCorners, shouldShowRoundedCorners,
getEventStart, getEventStart,
getEventThumbnail
}; };
}; };