From 35f99349a94864b793c3495ad3e3fc9de3148fe6 Mon Sep 17 00:00:00 2001 From: alma Date: Sun, 27 Apr 2025 22:42:07 +0200 Subject: [PATCH] courrier multi account restore compose --- app/courrier/page.tsx | 4 +-- components/email/ComposeEmail.tsx | 52 ++++++++++++++++++++++++++++++- 2 files changed, 53 insertions(+), 3 deletions(-) diff --git a/app/courrier/page.tsx b/app/courrier/page.tsx index 50c4fcbe..b29f7a45 100644 --- a/app/courrier/page.tsx +++ b/app/courrier/page.tsx @@ -920,7 +920,7 @@ export default function CourrierPage() {
{account.name} {account.id !== 'all-accounts' && ( - + )} diff --git a/components/email/ComposeEmail.tsx b/components/email/ComposeEmail.tsx index 242ef1ca..2b425e7f 100644 --- a/components/email/ComposeEmail.tsx +++ b/components/email/ComposeEmail.tsx @@ -359,6 +359,56 @@ export default function ComposeEmail(props: ComposeEmailAllProps) { } }, []); + // Add missing references and handlers + const editorRef = useRef(null); + const attachmentInputRef = useRef(null); + + // Handle editor input + const handleEditorInput = (e: React.FormEvent) => { + setEmailContent(e.currentTarget.innerHTML); + }; + + // Handle attachment click + const handleAttachmentClick = () => { + attachmentInputRef.current?.click(); + }; + + // Handle file selection + const handleFileSelection = (e: React.ChangeEvent) => { + const files = e.target.files; + if (!files || files.length === 0) return; + + // Process selected files + for (const file of files) { + const reader = new FileReader(); + + reader.onload = (event) => { + const content = event.target?.result as string; + + setAttachments(current => [ + ...current, + { + name: file.name, + content: content.split(',')[1], // Remove data:mime/type;base64, prefix + type: file.type + } + ]); + }; + + reader.readAsDataURL(file); + } + + // Reset file input + if (e.target) { + e.target.value = ''; + } + }; + + // Remove attachment + const removeAttachment = (index: number) => { + setAttachments(current => current.filter((_, i) => i !== index)); + }; + return (
@@ -466,7 +516,7 @@ export default function ComposeEmail(props: ComposeEmailAllProps) { className="flex-1 overflow-auto p-4 focus:outline-none email-content" contentEditable={true} onInput={handleEditorInput} - dangerouslySetInnerHTML={{ __html: body }} + dangerouslySetInnerHTML={{ __html: emailContent }} style={{ minHeight: '200px' }} />