mirror of
https://github.com/ramvignesh-b/pi-ku.git
synced 2026-05-04 08:56:52 +00:00
feat: implement letter sealing UI with save confirmation
This commit is contained in:
@@ -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 type { FabricObject } from "fabric";
|
||||||
import { useRef, useState } from "react";
|
import { useRef, useState } from "react";
|
||||||
import { api } from "../api/apiClient";
|
import { api } from "../api/apiClient";
|
||||||
@@ -12,6 +17,10 @@ import { useKeyStore } from "../store/useKeyStore";
|
|||||||
import { CryptoUtils } from "../utils/crypto";
|
import { CryptoUtils } from "../utils/crypto";
|
||||||
|
|
||||||
export default function Editor() {
|
export default function Editor() {
|
||||||
|
const [_letterId] = useState(() => crypto.randomUUID());
|
||||||
|
const [isSealing, setIsSealing] = useState(false);
|
||||||
|
const [isSaveSuccess, setIsSaveSuccess] = useState(false);
|
||||||
|
|
||||||
const [recipient, setRecipient] = useState("");
|
const [recipient, setRecipient] = useState("");
|
||||||
const masterKey = useKeyStore.getState().masterKey;
|
const masterKey = useKeyStore.getState().masterKey;
|
||||||
|
|
||||||
@@ -26,6 +35,8 @@ export default function Editor() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
async function handleSeal(): Promise<void> {
|
async function handleSeal(): Promise<void> {
|
||||||
|
if (isSealing) return;
|
||||||
|
setIsSealing(true);
|
||||||
const cryptoUtils = new CryptoUtils();
|
const cryptoUtils = new CryptoUtils();
|
||||||
await cryptoUtils.initialize();
|
await cryptoUtils.initialize();
|
||||||
|
|
||||||
@@ -63,8 +74,6 @@ export default function Editor() {
|
|||||||
const encrypted_metadata = "";
|
const encrypted_metadata = "";
|
||||||
|
|
||||||
// upload to server
|
// upload to server
|
||||||
|
|
||||||
// sample payload
|
|
||||||
/*
|
/*
|
||||||
payload = {
|
payload = {
|
||||||
"type": "SENT",
|
"type": "SENT",
|
||||||
@@ -84,11 +93,40 @@ export default function Editor() {
|
|||||||
encImageFilesMap.forEach((image, filename) => {
|
encImageFilesMap.forEach((image, filename) => {
|
||||||
formData.append("image_files", image, filename);
|
formData.append("image_files", image, filename);
|
||||||
});
|
});
|
||||||
|
try {
|
||||||
await api.post(endpoints.LETTERS, formData);
|
await api.post(endpoints.LETTERS, formData);
|
||||||
|
setIsSaveSuccess(true);
|
||||||
|
setTimeout(() => {
|
||||||
|
setIsSaveSuccess(false);
|
||||||
|
}, 5000);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error sealing letter:", error);
|
||||||
|
} finally {
|
||||||
|
setIsSealing(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<section className="flex-1 overflow-y-auto scrollbar-hide px-2 py-12 bg-base-300">
|
<section className="flex-1 overflow-y-auto scrollbar-hide px-2 py-12 bg-base-300">
|
||||||
|
{isSaveSuccess && (
|
||||||
|
<div className="modal modal-open">
|
||||||
|
<div className="modal-box">
|
||||||
|
<div className="alert alert-success">
|
||||||
|
<DownloadSimpleIcon size={18} weight="bold" />
|
||||||
|
<h3 className="font-bold text-lg">Letter saved successfully!</h3>
|
||||||
|
</div>
|
||||||
|
<div className="modal-action">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="btn btn-primary"
|
||||||
|
onClick={() => setIsSaveSuccess(false)}
|
||||||
|
>
|
||||||
|
Close
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
<div className="max-w-[720px] mx-auto px-1 md:px-0">
|
<div className="max-w-[720px] mx-auto px-1 md:px-0">
|
||||||
<div className="flex justify-between items-end mb-16 border-b border-base-content/5 pb-8 px-0">
|
<div className="flex justify-between items-end mb-16 border-b border-base-content/5 pb-8 px-0">
|
||||||
<div className="flex flex-col gap-2 flex-1">
|
<div className="flex flex-col gap-2 flex-1">
|
||||||
|
|||||||
Reference in New Issue
Block a user