2024-02-11 16:23:45 +03:00
|
|
|
import { baseUrl } from "@/api/baseUrl";
|
|
|
|
|
import { Event as FrigateEvent } from "@/types/event";
|
|
|
|
|
import TimeAgo from "../dynamic/TimeAgo";
|
|
|
|
|
import { Tooltip, TooltipContent, TooltipTrigger } from "../ui/tooltip";
|
2024-02-13 04:28:36 +03:00
|
|
|
import { useMemo } from "react";
|
|
|
|
|
import { useApiHost } from "@/api";
|
|
|
|
|
import useSWR from "swr";
|
|
|
|
|
import { FrigateConfig } from "@/types/frigateConfig";
|
2024-02-11 16:23:45 +03:00
|
|
|
|
|
|
|
|
type AnimatedEventThumbnailProps = {
|
|
|
|
|
event: FrigateEvent;
|
|
|
|
|
};
|
|
|
|
|
export function AnimatedEventThumbnail({ event }: AnimatedEventThumbnailProps) {
|
2024-02-13 04:28:36 +03:00
|
|
|
const apiHost = useApiHost();
|
|
|
|
|
const { data: config } = useSWR<FrigateConfig>("config");
|
|
|
|
|
|
|
|
|
|
const imageUrl = useMemo(() => {
|
|
|
|
|
if (Date.now() / 1000 < event.start_time + 20) {
|
|
|
|
|
return `${apiHost}api/preview/${event.camera}/${event.start_time}/thumbnail.jpg`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return `${baseUrl}api/events/${event.id}/preview.gif`;
|
|
|
|
|
}, [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-15 03:19:55 +03:00
|
|
|
className="h-24 relative rounded bg-cover bg-no-repeat bg-center mr-4"
|
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 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>
|
|
|
|
|
{`${event.label} ${
|
|
|
|
|
event.sub_label ? `(${event.sub_label})` : ""
|
|
|
|
|
} detected with score of ${(event.data.score * 100).toFixed(0)}% ${
|
|
|
|
|
event.data.sub_label_score
|
|
|
|
|
? `(${event.data.sub_label_score * 100}%)`
|
|
|
|
|
: ""
|
|
|
|
|
}`}
|
|
|
|
|
</TooltipContent>
|
|
|
|
|
</Tooltip>
|
|
|
|
|
);
|
|
|
|
|
}
|