import { baseUrl } from "@/api/baseUrl"; import ActivityIndicator from "@/components/indicators/activity-indicator"; 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"; import { useCallback, useMemo, useState } from "react"; import { TransformWrapper, TransformComponent } from "react-zoom-pan-pinch"; import useSWR from "swr"; type SubmissionState = "reviewing" | "uploading" | "submitted"; type FrigatePlusDialogProps = { upload?: Event; dialog?: boolean; onClose: () => void; onEventUploaded: () => void; }; export function FrigatePlusDialog({ upload, dialog = true, onClose, onEventUploaded, }: FrigatePlusDialogProps) { const { data: config } = useSWR("config"); // layout 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 const [state, setState] = useState( upload?.plus_id ? "submitted" : "reviewing", ); 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, }); setState("submitted"); onEventUploaded(); onClose(); }, [upload, onClose, onEventUploaded], ); const content = ( Submit To Frigate+ Objects in locations you want to avoid are not false positives. Submitting them as false positives will confuse the model. {upload?.id && ( {`${upload?.label}`} )} {state == "reviewing" && ( <> {dialog && } )} {state == "uploading" && } ); if (dialog) { return ( (!open ? onClose() : null)} > {content} ); } return content; }