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]);
|
|
|
|
|
|
|
|
|
|
const aspect = useMemo(() => {
|
|
|
|
|
if (!config) {
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const detect = config.cameras[event.camera].detect;
|
|
|
|
|
const aspect = detect.width / detect.height;
|
|
|
|
|
|
|
|
|
|
if (aspect > 2) {
|
|
|
|
|
return "aspect-wide";
|
|
|
|
|
} else if (aspect < 1) {
|
|
|
|
|
return "aspect-tall";
|
|
|
|
|
} else {
|
|
|
|
|
return "aspect-video";
|
|
|
|
|
}
|
|
|
|
|
}, [config, event]);
|
|
|
|
|
|
2024-02-11 16:23:45 +03:00
|
|
|
return (
|
|
|
|
|
<Tooltip>
|
|
|
|
|
<TooltipTrigger asChild>
|
|
|
|
|
<div
|
2024-02-13 04:28:36 +03:00
|
|
|
className={`relative rounded bg-cover h-24 bg-no-repeat bg-center mr-4 ${aspect}`}
|
2024-02-11 16:23:45 +03:00
|
|
|
style={{
|
2024-02-13 04:28:36 +03:00
|
|
|
backgroundImage: `url(${imageUrl})`,
|
2024-02-11 16:23:45 +03:00
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<div className="absolute bottom-0 w-full h-6 bg-gradient-to-t from-slate-900/50 to-transparent rounded">
|
|
|
|
|
<div className="absolute left-1 bottom-0 text-xs text-white w-full">
|
|
|
|
|
<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>
|
|
|
|
|
);
|
|
|
|
|
}
|