blakeblackshear.frigate/web/src/components/timeline/SummarySegment.tsx

71 lines
2.0 KiB
TypeScript
Raw Normal View History

import { useEventSegmentUtils } from "@/hooks/use-event-segment-utils";
2024-03-21 15:00:04 +01:00
import { ReviewSegment, ReviewSeverity } from "@/types/review";
import React, { useMemo } from "react";
// import useTapUtils from "@/hooks/use-tap-utils";
type SummarySegmentProps = {
events: ReviewSegment[];
segmentTime: number;
segmentDuration: number;
segmentHeight: number;
2024-03-21 15:00:04 +01:00
severityType: ReviewSeverity;
};
export function SummarySegment({
events,
segmentTime,
segmentDuration,
segmentHeight,
2024-03-21 15:00:04 +01:00
severityType,
}: SummarySegmentProps) {
const { getSeverity, getReviewed, displaySeverityType } =
useEventSegmentUtils(segmentDuration, events, severityType);
const severity = useMemo(
() => getSeverity(segmentTime, displaySeverityType),
[getSeverity, segmentTime, displaySeverityType],
);
const reviewed = useMemo(
() => getReviewed(segmentTime),
[getReviewed, segmentTime],
);
const segmentKey = useMemo(() => segmentTime, [segmentTime]);
const severityColors: { [key: number]: string } = {
1: reviewed
? "bg-severity_significant_motion/50"
: "bg-severity_significant_motion",
2: reviewed ? "bg-severity_detection/50" : "bg-severity_detection",
3: reviewed ? "bg-severity_alert/50" : "bg-severity_alert",
};
return (
<div
key={segmentKey}
className="relative w-full"
style={{ height: segmentHeight }}
>
2024-03-21 15:00:04 +01:00
{severity.map((severityValue: number, index: number) => (
<React.Fragment key={index}>
{severityValue === displaySeverityType && (
<div
className="flex justify-end cursor-pointer"
style={{ height: segmentHeight }}
>
<div
key={`${segmentKey}_${index}_secondary_data`}
style={{ height: segmentHeight }}
className={`w-[10px] ${severityColors[severityValue]}`}
></div>
</div>
2024-03-21 15:00:04 +01:00
)}
</React.Fragment>
))}
</div>
);
}
export default SummarySegment;