* Fix using undefined search params

* Fix calendar selection

* Simplify
This commit is contained in:
Nicolas Mowen 2024-05-28 12:15:31 -06:00 committed by GitHub
parent f7c3ddd380
commit 4236580672
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 32 additions and 27 deletions

View File

@ -69,7 +69,7 @@ export default function AutoUpdatingCameraImage({
<CameraImage <CameraImage
camera={camera} camera={camera}
onload={handleLoad} onload={handleLoad}
searchParams={`cache=${key}&${searchParams}`} searchParams={`cache=${key}${searchParams && `&${searchParams}`}`}
className={cameraClasses} className={cameraClasses}
/> />
{showFps ? <span className="text-xs">Displaying at {fps}fps</span> : null} {showFps ? <span className="text-xs">Displaying at {fps}fps</span> : null}

View File

@ -3,6 +3,7 @@ import { Calendar } from "../ui/calendar";
import { useMemo } from "react"; import { useMemo } from "react";
import { FaCircle } from "react-icons/fa"; import { FaCircle } from "react-icons/fa";
import { getUTCOffset } from "@/utils/dateUtil"; import { getUTCOffset } from "@/utils/dateUtil";
import { type DayContentProps } from "react-day-picker";
type ReviewActivityCalendarProps = { type ReviewActivityCalendarProps = {
reviewSummary?: ReviewSummary; reviewSummary?: ReviewSummary;
@ -22,6 +23,28 @@ export default function ReviewActivityCalendar({
return { from: tomorrow, to: future }; return { from: tomorrow, to: future };
}, []); }, []);
const modifiers = useMemo(() => {
if (!reviewSummary) {
return { alerts: [], detections: [] };
}
const unreviewedDetections: Date[] = [];
const unreviewedAlerts: Date[] = [];
Object.entries(reviewSummary).forEach(([date, data]) => {
if (data.total_alert > data.reviewed_alert) {
unreviewedAlerts.push(new Date(date));
} else if (data.total_detection > data.reviewed_detection) {
unreviewedDetections.push(new Date(date));
}
});
return {
alerts: unreviewedAlerts,
detections: unreviewedDetections,
};
}, [reviewSummary]);
return ( return (
<Calendar <Calendar
mode="single" mode="single"
@ -29,46 +52,28 @@ export default function ReviewActivityCalendar({
showOutsideDays={false} showOutsideDays={false}
selected={selectedDay} selected={selectedDay}
onSelect={onSelect} onSelect={onSelect}
modifiers={modifiers}
components={{ components={{
DayContent: (date) => ( DayContent: ReviewActivityDay,
<ReviewActivityDay reviewSummary={reviewSummary} day={date.date} />
),
}} }}
/> />
); );
} }
type ReviewActivityDayProps = { function ReviewActivityDay({ date, activeModifiers }: DayContentProps) {
reviewSummary?: ReviewSummary;
day: Date;
};
function ReviewActivityDay({ reviewSummary, day }: ReviewActivityDayProps) {
const dayActivity = useMemo(() => { const dayActivity = useMemo(() => {
if (!reviewSummary) { if (activeModifiers["alerts"]) {
return "none";
}
const allActivity =
reviewSummary[
`${day.getFullYear()}-${("0" + (day.getMonth() + 1)).slice(-2)}-${("0" + day.getDate()).slice(-2)}`
];
if (!allActivity) {
return "none";
}
if (allActivity.total_alert > allActivity.reviewed_alert) {
return "alert"; return "alert";
} else if (allActivity.total_detection > allActivity.reviewed_detection) { } else if (activeModifiers["detections"]) {
return "detection"; return "detection";
} else { } else {
return "none"; return "none";
} }
}, [reviewSummary, day]); }, [activeModifiers]);
return ( return (
<div className="flex flex-col items-center justify-center"> <div className="flex flex-col items-center justify-center gap-0.5">
{day.getDate()} {date.getDate()}
{dayActivity != "none" && ( {dayActivity != "none" && (
<FaCircle <FaCircle
className={`size-2 ${dayActivity == "alert" ? "fill-severity_alert" : "fill-severity_detection"}`} className={`size-2 ${dayActivity == "alert" ? "fill-severity_alert" : "fill-severity_detection"}`}