diff --git a/components/ComposeEmail.tsx b/components/ComposeEmail.tsx index 7eae1be5..840281d6 100644 --- a/components/ComposeEmail.tsx +++ b/components/ComposeEmail.tsx @@ -82,59 +82,42 @@ export default function ComposeEmail({ useEffect(() => { if (composeBodyRef.current) { - // Initialize the content structure - const originalContent = replyTo || forwardFrom ? ` -
-
+ // 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} -
- ` : composeBody; + + ` : ''; - composeBodyRef.current.innerHTML = originalContent; + composeBodyRef.current.innerHTML = content; - // Place cursor at the beginning of new reply area - const newReplyArea = composeBodyRef.current.querySelector('#new-reply-area'); - if (newReplyArea) { - const range = document.createRange(); - const sel = window.getSelection(); - range.setStart(newReplyArea, 0); - range.collapse(true); - sel?.removeAllRanges(); - sel?.addRange(range); - } + // Place cursor at the beginning + const range = document.createRange(); + const sel = window.getSelection(); + range.setStart(composeBodyRef.current, 0); + range.collapse(true); + sel?.removeAllRanges(); + sel?.addRange(range); } }, [composeBody, replyTo, forwardFrom]); - // Modified input handler to prevent nested structures + // Modified input handler to work with the single contentEditable area const handleInput = (e: React.FormEvent) => { if (!composeBodyRef.current) return; - - // Get the new reply content - const newReplyArea = composeBodyRef.current.querySelector('#new-reply-area'); - const originalEmailArea = composeBodyRef.current.querySelector('#original-email'); - - if (!newReplyArea || !originalEmailArea) return; - - const newReplyContent = newReplyArea.innerHTML; - const originalContent = originalEmailArea.innerHTML; - - // Update local state - setComposeBody(newReplyContent); - - // Combine both contents while maintaining formatting - const formattedContent = ` -
- ${newReplyContent} -
-
- ${originalContent} -
- `; - - // Update the compose form - if (onBodyChange) { - onBodyChange(formattedContent); - } + setComposeBody(composeBodyRef.current.innerHTML); }; const handleFileAttachment = async (e: React.ChangeEvent) => { @@ -274,22 +257,7 @@ export default function ComposeEmail({ /> - {/* Original Email Content Preview - Move it above the message body */} - {(replyTo || forwardFrom) && ( -
-
-

- {forwardFrom ? 'Forwarded Message' : 'Original Message'} -

-
-
-
- )} - - {/* Message Body */} + {/* Message Body - Single contentEditable area */}