From a07e7a0923a53aa261ce79d04806f54b9718bd41 Mon Sep 17 00:00:00 2001 From: Josh Hawkins <32435876+hawkeye217@users.noreply.github.com> Date: Wed, 23 Apr 2025 17:38:40 -0500 Subject: [PATCH] frontend and i18n keys --- web/public/locales/en/views/faceLibrary.json | 8 ++ web/src/pages/FaceLibrary.tsx | 100 +++++++++++++++++-- 2 files changed, 97 insertions(+), 11 deletions(-) diff --git a/web/public/locales/en/views/faceLibrary.json b/web/public/locales/en/views/faceLibrary.json index da6c44ff33..ee1cd3425e 100644 --- a/web/public/locales/en/views/faceLibrary.json +++ b/web/public/locales/en/views/faceLibrary.json @@ -36,9 +36,15 @@ "title": "Delete Name", "desc": "Are you sure you want to delete the collection {{name}}? This will permanently delete all associated faces." }, + "renameFace": { + "title": "Rename Face", + "desc": "Enter a new name for {{name}}" + }, "button": { "deleteFaceAttempts": "Delete Face Attempts", "addFace": "Add Face", + "renameFace": "Rename Face", + "deleteFace": "Delete Face", "uploadImage": "Upload Image", "reprocessFace": "Reprocess Face" }, @@ -62,6 +68,7 @@ "deletedName_zero": "Empty collection deleted successfully.", "deletedName_one": "{{count}} face has been successfully deleted.", "deletedName_other": "{{count}} faces have been successfully deleted.", + "renamedFace": "Successfully renamed face to {{name}}", "trainedFace": "Successfully trained face.", "updatedFaceScore": "Successfully updated face score." }, @@ -70,6 +77,7 @@ "addFaceLibraryFailed": "Failed to set face name: {{errorMessage}}", "deleteFaceFailed": "Failed to delete: {{errorMessage}}", "deleteNameFailed": "Failed to delete name: {{errorMessage}}", + "renameFaceFailed": "Failed to rename face: {{errorMessage}}", "trainFailed": "Failed to train: {{errorMessage}}", "updateFaceScoreFailed": "Failed to update face score: {{errorMessage}}" } diff --git a/web/src/pages/FaceLibrary.tsx b/web/src/pages/FaceLibrary.tsx index 4b5b7ae9a4..51defc9720 100644 --- a/web/src/pages/FaceLibrary.tsx +++ b/web/src/pages/FaceLibrary.tsx @@ -3,6 +3,7 @@ import TimeAgo from "@/components/dynamic/TimeAgo"; import AddFaceIcon from "@/components/icons/AddFaceIcon"; import ActivityIndicator from "@/components/indicators/activity-indicator"; import CreateFaceWizardDialog from "@/components/overlay/detail/FaceCreateWizardDialog"; +import TextEntryDialog from "@/components/overlay/dialog/TextEntryDialog"; import UploadImageDialog from "@/components/overlay/dialog/UploadImageDialog"; import FaceSelectionDialog from "@/components/overlay/FaceSelectionDialog"; import { Button } from "@/components/ui/button"; @@ -41,6 +42,7 @@ import { isDesktop, isMobile } from "react-device-detect"; import { useTranslation } from "react-i18next"; import { LuImagePlus, + LuPencil, LuRefreshCw, LuScanFace, LuSearch, @@ -221,6 +223,32 @@ export default function FaceLibrary() { [faceImages, refreshFaces, setPageToggle, t], ); + const onRename = useCallback( + (oldName: string, newName: string) => { + axios + .put(`/faces/${oldName}/rename`, { new_name: newName }) + .then((resp) => { + if (resp.status === 200) { + toast.success(t("toast.success.renamedFace", { name: newName }), { + position: "top-center", + }); + setPageToggle("train"); + refreshFaces(); + } + }) + .catch((error) => { + const errorMessage = + error.response?.data?.message || + error.response?.data?.detail || + "Unknown error"; + toast.error(t("toast.error.renameFaceFailed", { errorMessage }), { + position: "top-center", + }); + }); + }, + [setPageToggle, refreshFaces, t], + ); + // keyboard useKeyboardListener(["a", "Escape"], (key, modifiers) => { @@ -274,6 +302,7 @@ export default function FaceLibrary() { trainImages={trainImages} setPageToggle={setPageToggle} onDelete={onDelete} + onRename={onRename} /> {selectedFaces?.length > 0 ? (