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-16 14:06:02 +03:00
|
|
|
import { LuClock } 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-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-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
|
|
|
|
|
className="cursor-pointer my-2 xs:mr-2 bg-secondary w-full xs:w-[48%] sm:w-[284px]"
|
|
|
|
|
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">
|
|
|
|
|
<div className="text-sm flex">
|
|
|
|
|
<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",
|
|
|
|
|
})}
|
|
|
|
|
</div>
|
|
|
|
|
<div className="capitalize text-sm flex align-center mt-1">
|
|
|
|
|
<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>
|
|
|
|
|
);
|
|
|
|
|
}
|