From d62b6d2a34daa3b17769b162abc58997353bb071 Mon Sep 17 00:00:00 2001 From: alma Date: Mon, 21 Apr 2025 22:39:26 +0200 Subject: [PATCH] mail page fix design dang --- components/ComposeEmail.tsx | 85 ++++++++++++++++++++++++------------- 1 file changed, 55 insertions(+), 30 deletions(-) diff --git a/components/ComposeEmail.tsx b/components/ComposeEmail.tsx index 840281d6..6cdeaf2a 100644 --- a/components/ComposeEmail.tsx +++ b/components/ComposeEmail.tsx @@ -79,45 +79,54 @@ export default function ComposeEmail({ }: ComposeEmailProps) { const composeBodyRef = useRef(null); const [localContent, setLocalContent] = useState(''); + const [isInitialized, setIsInitialized] = useState(false); useEffect(() => { - if (composeBodyRef.current) { + if (composeBodyRef.current && !isInitialized) { // 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} -
+
+
+ ${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); - // 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); + // Place cursor at the beginning of the compose area + const composeArea = composeBodyRef.current.querySelector('.compose-area'); + if (composeArea) { + const range = document.createRange(); + const sel = window.getSelection(); + range.setStart(composeArea, 0); + range.collapse(true); + sel?.removeAllRanges(); + sel?.addRange(range); + } } - }, [composeBody, replyTo, forwardFrom]); + }, [composeBody, replyTo, forwardFrom, isInitialized]); // Modified input handler to work with the single contentEditable area const handleInput = (e: React.FormEvent) => { if (!composeBodyRef.current) return; - setComposeBody(composeBodyRef.current.innerHTML); + const composeArea = composeBodyRef.current.querySelector('.compose-area'); + if (composeArea) { + setComposeBody(composeArea.innerHTML); + } }; const handleFileAttachment = async (e: React.ChangeEvent) => { @@ -257,13 +266,11 @@ export default function ComposeEmail({ /> - {/* Message Body - Single contentEditable area */} + {/* Message Body - Single contentEditable area with separated regions */}
+ > + +