2023-12-13 05:48:52 +03:00
|
|
|
import useSWR from "swr";
|
|
|
|
|
import PreviewThumbnailPlayer from "../player/PreviewThumbnailPlayer";
|
|
|
|
|
import { Card } from "../ui/card";
|
|
|
|
|
import { FrigateConfig } from "@/types/frigateConfig";
|
|
|
|
|
import ActivityIndicator from "../ui/activity-indicator";
|
2023-12-21 03:38:06 +03:00
|
|
|
import { LuClock, LuTrash } from "react-icons/lu";
|
2023-12-13 05:48:52 +03:00
|
|
|
import { HiOutlineVideoCamera } from "react-icons/hi";
|
|
|
|
|
import { formatUnixTimestampToDateTime } from "@/utils/dateUtil";
|
2023-12-16 14:06:02 +03:00
|
|
|
import {
|
|
|
|
|
getTimelineIcon,
|
|
|
|
|
getTimelineItemDescription,
|
|
|
|
|
} from "@/utils/timelineUtil";
|
2023-12-13 05:48:52 +03:00
|
|
|
|
|
|
|
|
type HistoryCardProps = {
|
|
|
|
|
timeline: Card;
|
2023-12-14 06:15:28 +03:00
|
|
|
relevantPreview?: Preview;
|
|
|
|
|
shouldAutoPlay: boolean;
|
2023-12-16 14:06:02 +03:00
|
|
|
onClick?: () => void;
|
2023-12-21 03:38:06 +03:00
|
|
|
onDelete?: () => void;
|
2023-12-13 05:48:52 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default function HistoryCard({
|
2023-12-14 06:15:28 +03:00
|
|
|
relevantPreview,
|
2023-12-13 05:48:52 +03:00
|
|
|
timeline,
|
2023-12-14 06:15:28 +03:00
|
|
|
shouldAutoPlay,
|
2023-12-16 14:06:02 +03:00
|
|
|
onClick,
|
2023-12-21 03:38:06 +03:00
|
|
|
onDelete,
|
2023-12-13 05:48:52 +03:00
|
|
|
}: HistoryCardProps) {
|
|
|
|
|
const { data: config } = useSWR<FrigateConfig>("config");
|
|
|
|
|
|
|
|
|
|
if (!config) {
|
|
|
|
|
return <ActivityIndicator />;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
2023-12-16 14:06:02 +03:00
|
|
|
<Card
|
2023-12-16 17:40:00 +03:00
|
|
|
className="cursor-pointer my-2 xs:mr-2 w-full xs:w-[48%] sm:w-[284px]"
|
2023-12-16 14:06:02 +03:00
|
|
|
onClick={onClick}
|
|
|
|
|
>
|
2023-12-13 05:48:52 +03:00
|
|
|
<PreviewThumbnailPlayer
|
|
|
|
|
camera={timeline.camera}
|
2023-12-14 06:15:28 +03:00
|
|
|
relevantPreview={relevantPreview}
|
2023-12-13 05:48:52 +03:00
|
|
|
startTs={Object.values(timeline.entries)[0].timestamp}
|
2023-12-14 06:15:28 +03:00
|
|
|
eventId={Object.values(timeline.entries)[0].source_id}
|
|
|
|
|
shouldAutoPlay={shouldAutoPlay}
|
2023-12-13 05:48:52 +03:00
|
|
|
/>
|
|
|
|
|
<div className="p-2">
|
2023-12-21 03:38:06 +03:00
|
|
|
<div className="text-sm flex justify-between items-center">
|
|
|
|
|
<div>
|
|
|
|
|
<LuClock className="h-5 w-5 mr-2 inline" />
|
|
|
|
|
{formatUnixTimestampToDateTime(timeline.time, {
|
|
|
|
|
strftime_fmt:
|
|
|
|
|
config.ui.time_format == "24hour" ? "%H:%M:%S" : "%I:%M:%S %p",
|
|
|
|
|
time_style: "medium",
|
|
|
|
|
date_style: "medium",
|
|
|
|
|
})}
|
|
|
|
|
</div>
|
|
|
|
|
<LuTrash
|
|
|
|
|
className="w-5 h-5 m-1 cursor-pointer"
|
|
|
|
|
stroke="#f87171"
|
|
|
|
|
onClick={(e: Event) => {
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
|
|
|
|
|
if (onDelete) {
|
|
|
|
|
onDelete();
|
|
|
|
|
}
|
|
|
|
|
}}
|
|
|
|
|
/>
|
2023-12-13 05:48:52 +03:00
|
|
|
</div>
|
2023-12-21 03:38:06 +03:00
|
|
|
<div className="capitalize text-sm flex items-center mt-1">
|
2023-12-13 05:48:52 +03:00
|
|
|
<HiOutlineVideoCamera className="h-5 w-5 mr-2 inline" />
|
|
|
|
|
{timeline.camera.replaceAll("_", " ")}
|
|
|
|
|
</div>
|
|
|
|
|
<div className="my-2 text-sm font-medium">Activity:</div>
|
|
|
|
|
{Object.entries(timeline.entries).map(([_, entry]) => {
|
|
|
|
|
return (
|
|
|
|
|
<div
|
|
|
|
|
key={entry.timestamp}
|
|
|
|
|
className="flex text-xs capitalize my-1 items-center"
|
|
|
|
|
>
|
|
|
|
|
{getTimelineIcon(entry)}
|
|
|
|
|
{getTimelineItemDescription(entry)}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
})}
|
|
|
|
|
</div>
|
|
|
|
|
</Card>
|
|
|
|
|
);
|
|
|
|
|
}
|