2024-03-06 13:24:21 +01:00
|
|
|
import { baseUrl } from "@/api/baseUrl";
|
2024-03-07 15:34:11 +01:00
|
|
|
import { Button } from "@/components/ui/button";
|
2024-03-06 13:24:21 +01:00
|
|
|
import {
|
2024-03-07 15:34:11 +01:00
|
|
|
Dialog,
|
|
|
|
DialogContent,
|
|
|
|
DialogDescription,
|
|
|
|
DialogFooter,
|
|
|
|
DialogHeader,
|
|
|
|
DialogTitle,
|
|
|
|
} from "@/components/ui/dialog";
|
2024-03-06 13:24:21 +01:00
|
|
|
import { Event } from "@/types/event";
|
|
|
|
import axios from "axios";
|
|
|
|
import { useCallback, useState } from "react";
|
|
|
|
import useSWR from "swr";
|
|
|
|
|
|
|
|
export default function SubmitPlus() {
|
|
|
|
const { data: events, mutate: refresh } = useSWR<Event[]>([
|
|
|
|
"events",
|
|
|
|
{ limit: 100, in_progress: 0, is_submitted: 0 },
|
|
|
|
]);
|
|
|
|
const [upload, setUpload] = useState<Event>();
|
|
|
|
|
|
|
|
const onSubmitToPlus = useCallback(
|
|
|
|
async (falsePositive: boolean) => {
|
|
|
|
if (!upload) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-03-07 15:34:11 +01:00
|
|
|
falsePositive
|
|
|
|
? axios.put(`events/${upload.id}/false_positive`)
|
|
|
|
: axios.post(`events/${upload.id}/plus`, {
|
2024-03-06 13:24:21 +01:00
|
|
|
include_annotation: 1,
|
|
|
|
});
|
|
|
|
|
2024-03-07 15:34:11 +01:00
|
|
|
refresh(
|
|
|
|
(data: Event[] | undefined) => {
|
|
|
|
if (!data) {
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
const index = data.findIndex((e) => e.id == upload.id);
|
|
|
|
|
|
|
|
if (index == -1) {
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
return [...data.slice(0, index), ...data.slice(index + 1)];
|
|
|
|
},
|
|
|
|
{ revalidate: false, populateCache: true },
|
|
|
|
);
|
|
|
|
setUpload(undefined);
|
2024-03-06 13:24:21 +01:00
|
|
|
},
|
|
|
|
[refresh, upload],
|
|
|
|
);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="size-full p-2 grid sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5 gap-2 overflow-auto">
|
2024-03-07 15:34:11 +01:00
|
|
|
<Dialog
|
2024-03-06 13:24:21 +01:00
|
|
|
open={upload != undefined}
|
|
|
|
onOpenChange={(open) => (!open ? setUpload(undefined) : null)}
|
|
|
|
>
|
2024-03-07 15:34:11 +01:00
|
|
|
<DialogContent className="md:max-w-4xl">
|
|
|
|
<DialogHeader>
|
|
|
|
<DialogTitle>Submit To Frigate+</DialogTitle>
|
|
|
|
<DialogDescription>
|
2024-03-06 13:24:21 +01:00
|
|
|
Objects in locations you want to avoid are not false positives.
|
|
|
|
Submitting them as false positives will confuse the model.
|
2024-03-07 15:34:11 +01:00
|
|
|
</DialogDescription>
|
|
|
|
</DialogHeader>
|
2024-03-06 13:24:21 +01:00
|
|
|
<img
|
|
|
|
className="flex-grow-0"
|
|
|
|
src={`${baseUrl}api/events/${upload?.id}/snapshot.jpg`}
|
|
|
|
alt={`${upload?.label}`}
|
|
|
|
/>
|
2024-03-07 15:34:11 +01:00
|
|
|
<DialogFooter>
|
|
|
|
<Button>Cancel</Button>
|
|
|
|
<Button
|
2024-03-06 13:24:21 +01:00
|
|
|
className="bg-success"
|
|
|
|
onClick={() => onSubmitToPlus(false)}
|
|
|
|
>
|
|
|
|
This is a {upload?.label}
|
2024-03-07 15:34:11 +01:00
|
|
|
</Button>
|
|
|
|
<Button variant="destructive" onClick={() => onSubmitToPlus(true)}>
|
2024-03-06 13:24:21 +01:00
|
|
|
This is not a {upload?.label}
|
2024-03-07 15:34:11 +01:00
|
|
|
</Button>
|
|
|
|
</DialogFooter>
|
|
|
|
</DialogContent>
|
|
|
|
</Dialog>
|
2024-03-06 13:24:21 +01:00
|
|
|
|
|
|
|
{events?.map((event) => {
|
|
|
|
return (
|
|
|
|
<div
|
2024-03-07 15:34:11 +01:00
|
|
|
className="size-full rounded-2xl flex justify-center items-center bg-black cursor-pointer"
|
2024-03-06 13:24:21 +01:00
|
|
|
onClick={() => setUpload(event)}
|
|
|
|
>
|
|
|
|
<img
|
2024-03-07 15:34:11 +01:00
|
|
|
className="aspect-video h-full object-contain rounded-2xl"
|
2024-03-06 13:24:21 +01:00
|
|
|
src={`${baseUrl}api/events/${event.id}/snapshot.jpg`}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
})}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|