From ed2752ad0bfaa11125e1fd9e63b460b5ba2c16d1 Mon Sep 17 00:00:00 2001 From: alma Date: Thu, 24 Apr 2025 17:05:48 +0200 Subject: [PATCH] mime change --- components/ComposeEmail.tsx | 271 +++++++++++++++++------------------- 1 file changed, 126 insertions(+), 145 deletions(-) diff --git a/components/ComposeEmail.tsx b/components/ComposeEmail.tsx index f3280bd7..6cdeaf2a 100644 --- a/components/ComposeEmail.tsx +++ b/components/ComposeEmail.tsx @@ -83,45 +83,26 @@ export default function ComposeEmail({ useEffect(() => { if (composeBodyRef.current && !isInitialized) { - let content = ''; - - if (replyTo) { - // For replies - content = ` -
-
-
- On ${new Date(replyTo.date).toLocaleString()}, ${replyTo.from} wrote: -
-
- ${composeBody} -
-
- `; - } else if (forwardFrom) { - // For forwards - content = ` -
-
-
- ---------- Forwarded message ---------
- From: ${forwardFrom.from}
- Date: ${new Date(forwardFrom.date).toLocaleString()}
- Subject: ${forwardFrom.subject}
- To: ${forwardFrom.to}
- ${forwardFrom.cc ? `Cc: ${forwardFrom.cc}
` : ''} -
-
- ${composeBody} -
-
- `; - } else { - // For new messages - content = ` -
- `; - } + // Initialize the content structure with both new reply area and original content in a single contentEditable div + const content = replyTo || forwardFrom ? ` +
+
+ ${forwardFrom ? ` + ---------- Forwarded message ---------
+ From: ${forwardFrom.from}
+ Date: ${new Date(forwardFrom.date).toLocaleString()}
+ Subject: ${forwardFrom.subject}
+ To: ${forwardFrom.to}
+ ${forwardFrom.cc ? `Cc: ${forwardFrom.cc}
` : ''} +
+ ` : ` + On ${new Date(replyTo?.date || '').toLocaleString()}, ${replyTo?.from} wrote:
+ `} +
+ ${composeBody} +
+
+ ` : ''; composeBodyRef.current.innerHTML = content; setIsInitialized(true); @@ -135,20 +116,16 @@ export default function ComposeEmail({ range.collapse(true); sel?.removeAllRanges(); sel?.addRange(range); - (composeArea as HTMLElement).focus(); } } }, [composeBody, replyTo, forwardFrom, isInitialized]); + // Modified input handler to work with the single contentEditable area const handleInput = (e: React.FormEvent) => { if (!composeBodyRef.current) return; const composeArea = composeBodyRef.current.querySelector('.compose-area'); if (composeArea) { - const newContent = composeArea.innerHTML; - setComposeBody(newContent); - if (onBodyChange) { - onBodyChange(newContent); - } + setComposeBody(composeArea.innerHTML); } }; @@ -166,11 +143,12 @@ export default function ComposeEmail({ } try { + // Read file as base64 const base64Content = await new Promise((resolve) => { const reader = new FileReader(); reader.onloadend = () => { const base64 = reader.result as string; - resolve(base64.split(',')[1]); + resolve(base64.split(',')[1]); // Remove data URL prefix }; reader.readAsDataURL(file); }); @@ -220,147 +198,150 @@ export default function ComposeEmail({
{/* To Field */}
- + setComposeTo(e.target.value)} - placeholder="Recipients" - className="mt-1" + placeholder="recipient@example.com" + className="w-full mt-1 bg-white border-gray-300 text-gray-900" />
- {/* Cc Field */} + {/* CC/BCC Toggle Buttons */} +
+ + +
+ + {/* CC Field */} {showCc && (
- + setComposeCc(e.target.value)} - placeholder="Carbon copy" - className="mt-1" + placeholder="cc@example.com" + className="w-full mt-1 bg-white border-gray-300 text-gray-900" />
)} - {/* Bcc Field */} + {/* BCC Field */} {showBcc && (
- + setComposeBcc(e.target.value)} - placeholder="Blind carbon copy" - className="mt-1" + placeholder="bcc@example.com" + className="w-full mt-1 bg-white border-gray-300 text-gray-900" />
)} {/* Subject Field */}
- + setComposeSubject(e.target.value)} - placeholder="Subject" - className="mt-1" + placeholder="Enter subject" + className="w-full mt-1 bg-white border-gray-300 text-gray-900" />
- {/* Message Body */} -
+ {/* Message Body - Single contentEditable area with separated regions */} +
+
-
- - {/* Attachments */} - {attachments.length > 0 && ( -
-
- {attachments.map((attachment, index) => ( -
- - {attachment.name} - -
- ))} -
-
- )} - - {/* Action Buttons */} -
-
- - {!showCc && ( - - )} - {!showBcc && ( - - )} -
-
- - + className="flex-1 w-full bg-white border border-gray-300 rounded-md p-4 text-gray-900 overflow-y-auto focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent" + style={{ direction: 'ltr' }} + dir="ltr" + spellCheck="true" + role="textbox" + aria-multiline="true" + tabIndex={0} + > +
+ + {/* Modal Footer */} +
+
+ {/* File Input for Attachments */} + + +
+
+ + +
+
);