From 70f46fae282c38935d1b541484b6e45996bb5b34 Mon Sep 17 00:00:00 2001 From: Weitheng Haw Date: Tue, 28 Jan 2025 09:16:56 +0000 Subject: [PATCH] Add ability to categorize face --- web/src/pages/FaceLibrary.tsx | 64 ++++++++++++++++++++++++++++++++--- 1 file changed, 59 insertions(+), 5 deletions(-) diff --git a/web/src/pages/FaceLibrary.tsx b/web/src/pages/FaceLibrary.tsx index 7b6abcffc..6bfb3abe3 100644 --- a/web/src/pages/FaceLibrary.tsx +++ b/web/src/pages/FaceLibrary.tsx @@ -23,9 +23,11 @@ import { cn } from "@/lib/utils"; import { FrigateConfig } from "@/types/frigateConfig"; import axios from "axios"; import { useCallback, useEffect, useMemo, useRef, useState } from "react"; -import { LuImagePlus, LuTrash2 } from "react-icons/lu"; +import { LuImagePlus, LuTrash2, LuUserPlus } from "react-icons/lu"; import { toast } from "sonner"; import useSWR from "swr"; +import { Input } from "@/components/ui/input"; +import { Dialog, DialogContent, DialogHeader, DialogTitle } from "@/components/ui/dialog"; export default function FaceLibrary() { const { data: config } = useSWR("config"); @@ -113,6 +115,32 @@ export default function FaceLibrary() { [pageToggle, refreshFaces], ); + const [newFaceDialog, setNewFaceDialog] = useState(false); + const [newFaceName, setNewFaceName] = useState(""); + + const createNewFace = useCallback(() => { + if (!newFaceName.trim()) { + toast.error("Face name cannot be empty", { position: "top-center" }); + return; + } + + axios + .post(`/faces/${newFaceName}`) + .then((resp) => { + if (resp.status == 200) { + setNewFaceDialog(false); + setNewFaceName(""); + refreshFaces(); + toast.success("Successfully created new face", { position: "top-center" }); + } + }) + .catch((error) => { + toast.error(`Failed to create face: ${error.response?.data?.message || error.message}`, { + position: "top-center", + }); + }); + }, [newFaceName, refreshFaces]); + if (!config) { return ; } @@ -121,6 +149,22 @@ export default function FaceLibrary() {
+ + + + Create New Face + +
+ setNewFaceName(e.target.value)} + /> + +
+
+
+
- +
+ + +
{pageToggle && (pageToggle == "train" ? (