Cleanup plus submission dialog

This commit is contained in:
Nicolas Mowen 2024-09-11 07:27:48 -06:00
parent 03a57fcc17
commit 1be82598bb
2 changed files with 40 additions and 17 deletions

View File

@ -151,7 +151,9 @@ export default function SearchDetailDialog({
upload={search as unknown as Event} upload={search as unknown as Event}
dialog={false} dialog={false}
onClose={() => {}} onClose={() => {}}
onEventUploaded={() => {}} onEventUploaded={() => {
search.plus_id = "new_upload";
}}
/> />
)} )}
{page == "video" && <VideoTab search={search} />} {page == "video" && <VideoTab search={search} />}

View File

@ -1,4 +1,5 @@
import { baseUrl } from "@/api/baseUrl"; import { baseUrl } from "@/api/baseUrl";
import ActivityIndicator from "@/components/indicators/activity-indicator";
import { Button } from "@/components/ui/button"; import { Button } from "@/components/ui/button";
import { import {
Dialog, Dialog,
@ -11,10 +12,12 @@ import {
import { Event } from "@/types/event"; import { Event } from "@/types/event";
import { FrigateConfig } from "@/types/frigateConfig"; import { FrigateConfig } from "@/types/frigateConfig";
import axios from "axios"; import axios from "axios";
import { useCallback, useMemo } from "react"; import { useCallback, useMemo, useState } from "react";
import { TransformWrapper, TransformComponent } from "react-zoom-pan-pinch"; import { TransformWrapper, TransformComponent } from "react-zoom-pan-pinch";
import useSWR from "swr"; import useSWR from "swr";
type SubmissionState = "reviewing" | "uploading" | "submitted";
type FrigatePlusDialogProps = { type FrigatePlusDialogProps = {
upload?: Event; upload?: Event;
dialog?: boolean; dialog?: boolean;
@ -51,6 +54,10 @@ export function FrigatePlusDialog({
// upload // upload
const [state, setState] = useState<SubmissionState>(
upload?.plus_id ? "submitted" : "reviewing",
);
const onSubmitToPlus = useCallback( const onSubmitToPlus = useCallback(
async (falsePositive: boolean) => { async (falsePositive: boolean) => {
if (!upload) { if (!upload) {
@ -63,6 +70,7 @@ export function FrigatePlusDialog({
include_annotation: 1, include_annotation: 1,
}); });
setState("submitted");
onEventUploaded(); onEventUploaded();
onClose(); onClose();
}, },
@ -97,21 +105,34 @@ export function FrigatePlusDialog({
/> />
)} )}
</TransformComponent> </TransformComponent>
{upload?.plus_id == undefined && (
<DialogFooter> <DialogFooter>
{state == "reviewing" && (
<>
{dialog && <Button onClick={onClose}>Cancel</Button>} {dialog && <Button onClick={onClose}>Cancel</Button>}
<Button className="bg-success" onClick={() => onSubmitToPlus(false)}> <Button
className="bg-success"
onClick={() => {
setState("uploading");
onSubmitToPlus(false);
}}
>
This is a {upload?.label} This is a {upload?.label}
</Button> </Button>
<Button <Button
className="text-white" className="text-white"
variant="destructive" variant="destructive"
onClick={() => onSubmitToPlus(true)} onClick={() => {
setState("uploading");
onSubmitToPlus(true);
}}
> >
This is not a {upload?.label} This is not a {upload?.label}
</Button> </Button>
</DialogFooter> </>
)} )}
{state == "uploading" && <ActivityIndicator />}
</DialogFooter>
</TransformWrapper> </TransformWrapper>
); );