2024-08-14 22:15:35 +03:00
|
|
|
import { baseUrl } from "@/api/baseUrl";
|
2024-09-11 17:41:16 +03:00
|
|
|
import ActivityIndicator from "@/components/indicators/activity-indicator";
|
2024-08-14 22:15:35 +03:00
|
|
|
import { Button } from "@/components/ui/button";
|
|
|
|
|
import {
|
|
|
|
|
Dialog,
|
|
|
|
|
DialogContent,
|
|
|
|
|
DialogDescription,
|
|
|
|
|
DialogFooter,
|
|
|
|
|
DialogHeader,
|
|
|
|
|
DialogTitle,
|
|
|
|
|
} from "@/components/ui/dialog";
|
|
|
|
|
import { Event } from "@/types/event";
|
|
|
|
|
import { FrigateConfig } from "@/types/frigateConfig";
|
|
|
|
|
import axios from "axios";
|
2024-10-02 17:32:12 +03:00
|
|
|
import { useCallback, useEffect, useMemo, useState } from "react";
|
2024-09-12 22:39:35 +03:00
|
|
|
import { isDesktop } from "react-device-detect";
|
2024-08-14 22:15:35 +03:00
|
|
|
import { TransformWrapper, TransformComponent } from "react-zoom-pan-pinch";
|
|
|
|
|
import useSWR from "swr";
|
|
|
|
|
|
2024-09-11 17:41:16 +03:00
|
|
|
type SubmissionState = "reviewing" | "uploading" | "submitted";
|
|
|
|
|
|
2024-08-14 22:15:35 +03:00
|
|
|
type FrigatePlusDialogProps = {
|
|
|
|
|
upload?: Event;
|
2024-09-11 17:41:16 +03:00
|
|
|
dialog?: boolean;
|
2024-08-14 22:15:35 +03:00
|
|
|
onClose: () => void;
|
|
|
|
|
onEventUploaded: () => void;
|
|
|
|
|
};
|
|
|
|
|
export function FrigatePlusDialog({
|
|
|
|
|
upload,
|
2024-09-11 17:41:16 +03:00
|
|
|
dialog = true,
|
2024-08-14 22:15:35 +03:00
|
|
|
onClose,
|
|
|
|
|
onEventUploaded,
|
|
|
|
|
}: FrigatePlusDialogProps) {
|
|
|
|
|
const { data: config } = useSWR<FrigateConfig>("config");
|
|
|
|
|
|
|
|
|
|
// layout
|
|
|
|
|
|
2024-09-12 22:39:35 +03:00
|
|
|
const Title = isDesktop ? DialogTitle : "div";
|
|
|
|
|
const Description = isDesktop ? DialogDescription : "div";
|
|
|
|
|
|
2024-08-14 22:15:35 +03:00
|
|
|
const grow = useMemo(() => {
|
|
|
|
|
if (!config || !upload) {
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const camera = config.cameras[upload.camera];
|
|
|
|
|
|
|
|
|
|
if (!camera) {
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (camera.detect.width / camera.detect.height < 16 / 9) {
|
|
|
|
|
return "aspect-video object-contain";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return "";
|
|
|
|
|
}, [config, upload]);
|
|
|
|
|
|
|
|
|
|
// upload
|
|
|
|
|
|
2024-09-11 17:41:16 +03:00
|
|
|
const [state, setState] = useState<SubmissionState>(
|
|
|
|
|
upload?.plus_id ? "submitted" : "reviewing",
|
|
|
|
|
);
|
|
|
|
|
|
2024-10-02 17:32:12 +03:00
|
|
|
useEffect(
|
|
|
|
|
() => setState(upload?.plus_id ? "submitted" : "reviewing"),
|
|
|
|
|
[upload],
|
|
|
|
|
);
|
|
|
|
|
|
2024-08-14 22:15:35 +03:00
|
|
|
const onSubmitToPlus = useCallback(
|
|
|
|
|
async (falsePositive: boolean) => {
|
|
|
|
|
if (!upload) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
falsePositive
|
|
|
|
|
? axios.put(`events/${upload.id}/false_positive`)
|
|
|
|
|
: axios.post(`events/${upload.id}/plus`, {
|
|
|
|
|
include_annotation: 1,
|
|
|
|
|
});
|
|
|
|
|
|
2024-09-11 17:41:16 +03:00
|
|
|
setState("submitted");
|
2024-08-14 22:15:35 +03:00
|
|
|
onEventUploaded();
|
|
|
|
|
onClose();
|
|
|
|
|
},
|
|
|
|
|
[upload, onClose, onEventUploaded],
|
|
|
|
|
);
|
|
|
|
|
|
2024-09-11 17:41:16 +03:00
|
|
|
const content = (
|
|
|
|
|
<TransformWrapper minScale={1.0} wheel={{ smoothStep: 0.005 }}>
|
2024-09-12 22:39:35 +03:00
|
|
|
<div className="flex flex-col space-y-3">
|
|
|
|
|
<DialogHeader
|
|
|
|
|
className={state == "submitted" ? "sr-only" : "text-left"}
|
|
|
|
|
>
|
|
|
|
|
<Title
|
|
|
|
|
className={
|
|
|
|
|
!isDesktop
|
|
|
|
|
? "text-lg font-semibold leading-none tracking-tight"
|
|
|
|
|
: undefined
|
|
|
|
|
}
|
|
|
|
|
>
|
|
|
|
|
Submit To Frigate+
|
|
|
|
|
</Title>
|
|
|
|
|
<Description
|
|
|
|
|
className={!isDesktop ? "text-sm text-muted-foreground" : undefined}
|
|
|
|
|
>
|
|
|
|
|
Objects in locations you want to avoid are not false positives.
|
|
|
|
|
Submitting them as false positives will confuse the model.
|
|
|
|
|
</Description>
|
|
|
|
|
</DialogHeader>
|
|
|
|
|
<TransformComponent
|
|
|
|
|
wrapperStyle={{
|
|
|
|
|
width: "100%",
|
|
|
|
|
height: "100%",
|
|
|
|
|
}}
|
|
|
|
|
contentStyle={{
|
|
|
|
|
position: "relative",
|
|
|
|
|
width: "100%",
|
|
|
|
|
height: "100%",
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
{upload?.id && (
|
|
|
|
|
<img
|
|
|
|
|
className={`w-full ${grow} bg-black`}
|
|
|
|
|
src={`${baseUrl}api/events/${upload?.id}/snapshot.jpg`}
|
|
|
|
|
alt={`${upload?.label}`}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
</TransformComponent>
|
|
|
|
|
|
|
|
|
|
<DialogFooter className="flex flex-row justify-end gap-2">
|
|
|
|
|
{state == "reviewing" && (
|
|
|
|
|
<>
|
2024-10-23 01:07:42 +03:00
|
|
|
{dialog && (
|
|
|
|
|
<Button aria-label="Cancel" onClick={onClose}>
|
|
|
|
|
Cancel
|
|
|
|
|
</Button>
|
|
|
|
|
)}
|
2024-09-12 22:39:35 +03:00
|
|
|
<Button
|
|
|
|
|
className="bg-success"
|
2024-10-23 01:07:42 +03:00
|
|
|
aria-label="Confirm this label for Frigate Plus"
|
2024-09-12 22:39:35 +03:00
|
|
|
onClick={() => {
|
|
|
|
|
setState("uploading");
|
|
|
|
|
onSubmitToPlus(false);
|
|
|
|
|
}}
|
|
|
|
|
>
|
2024-11-01 15:37:52 +03:00
|
|
|
This is {/^[aeiou]/i.test(upload?.label || "") ? "an" : "a"}{" "}
|
|
|
|
|
{upload?.label}
|
2024-09-12 22:39:35 +03:00
|
|
|
</Button>
|
|
|
|
|
<Button
|
|
|
|
|
className="text-white"
|
2024-10-23 01:07:42 +03:00
|
|
|
aria-label="Do not confirm this label for Frigate Plus"
|
2024-09-12 22:39:35 +03:00
|
|
|
variant="destructive"
|
|
|
|
|
onClick={() => {
|
|
|
|
|
setState("uploading");
|
|
|
|
|
onSubmitToPlus(true);
|
|
|
|
|
}}
|
|
|
|
|
>
|
2024-11-01 15:37:52 +03:00
|
|
|
This is not {/^[aeiou]/i.test(upload?.label || "") ? "an" : "a"}{" "}
|
|
|
|
|
{upload?.label}
|
2024-09-12 22:39:35 +03:00
|
|
|
</Button>
|
|
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
{state == "uploading" && <ActivityIndicator />}
|
|
|
|
|
</DialogFooter>
|
|
|
|
|
</div>
|
2024-09-11 17:41:16 +03:00
|
|
|
</TransformWrapper>
|
2024-08-14 22:15:35 +03:00
|
|
|
);
|
2024-09-11 17:41:16 +03:00
|
|
|
|
|
|
|
|
if (dialog) {
|
|
|
|
|
return (
|
|
|
|
|
<Dialog
|
|
|
|
|
open={upload != undefined}
|
|
|
|
|
onOpenChange={(open) => (!open ? onClose() : null)}
|
|
|
|
|
>
|
|
|
|
|
<DialogContent className="md:max-w-3xl lg:max-w-4xl xl:max-w-7xl">
|
|
|
|
|
{content}
|
|
|
|
|
</DialogContent>
|
|
|
|
|
</Dialog>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return content;
|
2024-08-14 22:15:35 +03:00
|
|
|
}
|