From 88686cdb0ff4359212a1934748a2da79d43024e2 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 12 Apr 2026 03:06:00 +0530 Subject: [PATCH] feat: implement letter sealing UI with save confirmation --- frontend/src/pages/Editor.tsx | 46 ++++++++++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 4 deletions(-) diff --git a/frontend/src/pages/Editor.tsx b/frontend/src/pages/Editor.tsx index 5ed6fa2..7a1e407 100644 --- a/frontend/src/pages/Editor.tsx +++ b/frontend/src/pages/Editor.tsx @@ -1,4 +1,9 @@ -import { ImageIcon, LockIcon, TrayIcon } from "@phosphor-icons/react"; +import { + DownloadSimpleIcon, + ImageIcon, + LockIcon, + TrayIcon, +} from "@phosphor-icons/react"; import type { FabricObject } from "fabric"; import { useRef, useState } from "react"; import { api } from "../api/apiClient"; @@ -12,6 +17,10 @@ import { useKeyStore } from "../store/useKeyStore"; import { CryptoUtils } from "../utils/crypto"; export default function Editor() { + const [_letterId] = useState(() => crypto.randomUUID()); + const [isSealing, setIsSealing] = useState(false); + const [isSaveSuccess, setIsSaveSuccess] = useState(false); + const [recipient, setRecipient] = useState(""); const masterKey = useKeyStore.getState().masterKey; @@ -26,6 +35,8 @@ export default function Editor() { }; async function handleSeal(): Promise { + if (isSealing) return; + setIsSealing(true); const cryptoUtils = new CryptoUtils(); await cryptoUtils.initialize(); @@ -63,8 +74,6 @@ export default function Editor() { const encrypted_metadata = ""; // upload to server - - // sample payload /* payload = { "type": "SENT", @@ -84,11 +93,40 @@ export default function Editor() { encImageFilesMap.forEach((image, filename) => { formData.append("image_files", image, filename); }); - await api.post(endpoints.LETTERS, formData); + try { + await api.post(endpoints.LETTERS, formData); + setIsSaveSuccess(true); + setTimeout(() => { + setIsSaveSuccess(false); + }, 5000); + } catch (error) { + console.error("Error sealing letter:", error); + } finally { + setIsSealing(false); + } } return (
+ {isSaveSuccess && ( +
+
+
+ +

Letter saved successfully!

+
+
+ +
+
+
+ )}