2024-02-11 16:23:45 +03:00
|
|
|
import { baseUrl } from "@/api/baseUrl";
|
|
|
|
|
import TimeAgo from "../dynamic/TimeAgo";
|
|
|
|
|
import { Tooltip, TooltipContent, TooltipTrigger } from "../ui/tooltip";
|
2024-02-28 23:24:34 +03:00
|
|
|
import { useCallback, useMemo } from "react";
|
2024-02-13 04:28:36 +03:00
|
|
|
import { useApiHost } from "@/api";
|
|
|
|
|
import useSWR from "swr";
|
|
|
|
|
import { FrigateConfig } from "@/types/frigateConfig";
|
2024-02-28 23:24:34 +03:00
|
|
|
import { ReviewSegment } from "@/types/review";
|
|
|
|
|
import { useNavigate } from "react-router-dom";
|
2024-02-11 16:23:45 +03:00
|
|
|
|
|
|
|
|
type AnimatedEventThumbnailProps = {
|
2024-02-28 23:24:34 +03:00
|
|
|
event: ReviewSegment;
|
2024-02-11 16:23:45 +03:00
|
|
|
};
|
|
|
|
|
export function AnimatedEventThumbnail({ event }: AnimatedEventThumbnailProps) {
|
2024-02-13 04:28:36 +03:00
|
|
|
const apiHost = useApiHost();
|
|
|
|
|
const { data: config } = useSWR<FrigateConfig>("config");
|
|
|
|
|
|
2024-02-28 23:24:34 +03:00
|
|
|
// interaction
|
|
|
|
|
|
|
|
|
|
const navigate = useNavigate();
|
|
|
|
|
const onOpenReview = useCallback(() => {
|
|
|
|
|
navigate("events", { state: { review: event.id } });
|
|
|
|
|
}, [navigate, event]);
|
|
|
|
|
|
|
|
|
|
// image behavior
|
|
|
|
|
|
2024-02-13 04:28:36 +03:00
|
|
|
const imageUrl = useMemo(() => {
|
|
|
|
|
if (Date.now() / 1000 < event.start_time + 20) {
|
|
|
|
|
return `${apiHost}api/preview/${event.camera}/${event.start_time}/thumbnail.jpg`;
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-28 23:24:34 +03:00
|
|
|
return `${baseUrl}api/review/${event.id}/preview.gif`;
|
2024-02-13 04:28:36 +03:00
|
|
|
}, [event]);
|
|
|
|
|
|
2024-02-15 03:19:55 +03:00
|
|
|
const aspectRatio = useMemo(() => {
|
2024-02-13 04:28:36 +03:00
|
|
|
if (!config) {
|
2024-02-15 03:19:55 +03:00
|
|
|
return 1;
|
2024-02-13 04:28:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const detect = config.cameras[event.camera].detect;
|
2024-02-15 03:19:55 +03:00
|
|
|
return detect.width / detect.height;
|
|
|
|
|
}, [config]);
|
2024-02-13 04:28:36 +03:00
|
|
|
|
2024-02-11 16:23:45 +03:00
|
|
|
return (
|
|
|
|
|
<Tooltip>
|
|
|
|
|
<TooltipTrigger asChild>
|
|
|
|
|
<div
|
2024-02-28 23:24:34 +03:00
|
|
|
className="h-24 relative rounded bg-cover bg-no-repeat bg-center mr-4 cursor-pointer"
|
2024-02-11 16:23:45 +03:00
|
|
|
style={{
|
2024-02-13 04:28:36 +03:00
|
|
|
backgroundImage: `url(${imageUrl})`,
|
2024-02-15 03:19:55 +03:00
|
|
|
aspectRatio: aspectRatio,
|
2024-02-11 16:23:45 +03:00
|
|
|
}}
|
2024-02-28 23:24:34 +03:00
|
|
|
onClick={onOpenReview}
|
2024-02-11 16:23:45 +03:00
|
|
|
>
|
2024-02-28 06:40:57 +03:00
|
|
|
<div className="absolute bottom-0 inset-x-0 h-6 bg-gradient-to-t from-slate-900/50 to-transparent rounded">
|
|
|
|
|
<div className="w-full absolute left-1 bottom-0 text-xs text-white">
|
2024-02-11 16:23:45 +03:00
|
|
|
<TimeAgo time={event.start_time * 1000} dense />
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</TooltipTrigger>
|
|
|
|
|
<TooltipContent>
|
2024-02-28 23:24:34 +03:00
|
|
|
{`${[...event.data.objects, ...event.data.audio, ...(event.data.sub_labels || [])].join(", ")} detected`}
|
2024-02-11 16:23:45 +03:00
|
|
|
</TooltipContent>
|
|
|
|
|
</Tooltip>
|
|
|
|
|
);
|
|
|
|
|
}
|