From 4db3140ece22720cb356c79daafe0cd0f8ea6356 Mon Sep 17 00:00:00 2001 From: alma Date: Sat, 26 Apr 2025 12:12:43 +0200 Subject: [PATCH] courrier clean 2 --- app/globals.css | 20 ++++++ components/ComposeEmail.tsx | 123 ++++++++++++++++++++++++++++-------- 2 files changed, 118 insertions(+), 25 deletions(-) diff --git a/app/globals.css b/app/globals.css index 5e1139c4..b870f517 100644 --- a/app/globals.css +++ b/app/globals.css @@ -88,3 +88,23 @@ .email-content .header { margin-bottom: 1em; } .email-content .footer { font-size: 0.875rem; color: #6b7280; margin-top: 1em; } +/* Force email content direction */ +.email-content-wrapper { + direction: ltr !important; + unicode-bidi: isolate !important; + text-align: left !important; +} + +.email-content-wrapper * { + direction: ltr !important; + unicode-bidi: isolate !important; + text-align: left !important; +} + +/* Email editor styles */ +.email-editor { + direction: ltr !important; + unicode-bidi: isolate !important; + text-align: left !important; +} + diff --git a/components/ComposeEmail.tsx b/components/ComposeEmail.tsx index 99f46ec3..61b8ab25 100644 --- a/components/ComposeEmail.tsx +++ b/components/ComposeEmail.tsx @@ -88,6 +88,8 @@ export default function ComposeEmail({ const fileInputRef = useRef(null); const contentEditableRef = useRef(null); const [useRichEditor, setUseRichEditor] = useState(false); + const [userMessage, setUserMessage] = useState(''); + const [quotedContent, setQuotedContent] = useState(''); useEffect(() => { // When forwarding or replying, use rich editor @@ -102,17 +104,16 @@ export default function ComposeEmail({ setComposeTo(formattedEmail.to); setComposeSubject(formattedEmail.subject); - // Use the body but preserve the original UI styling - // Extract just the content portion from the client formatter output - // and apply the original styling - let bodyContent = formattedEmail.body; - - // Apply DOMPurify to the content for safety - bodyContent = DOMPurify.sanitize(bodyContent, { + // Store the quoted content separately + const bodyContent = DOMPurify.sanitize(formattedEmail.body, { ADD_TAGS: ['style'], FORBID_TAGS: ['script', 'iframe'] }); + setQuotedContent(bodyContent); + setUserMessage(''); // Clear user input + + // Keep composeBody for backwards compatibility setComposeBody(bodyContent); } }, [replyTo, setComposeTo, setComposeSubject, setComposeBody]); @@ -162,13 +163,23 @@ export default function ComposeEmail({ }); } - // Set body with header and content, preserving the original UI layout - setComposeBody(` - ${headerHtml} -
- ${contentHtml} + // Store the quoted content + const formattedQuote = ` +
+ ${headerHtml} +
+
+ ${contentHtml} +
+
- `); + `; + + setQuotedContent(formattedQuote); + setUserMessage(''); // Clear user input + + // Keep composeBody for backwards compatibility + setComposeBody(formattedQuote); }; // Handle file attachment selection @@ -180,9 +191,44 @@ export default function ComposeEmail({ }; // Handle contentEditable input changes - const handleContentEditableChange = () => { + const handleUserMessageChange = () => { if (contentEditableRef.current) { - setComposeBody(contentEditableRef.current.innerHTML); + setUserMessage(contentEditableRef.current.innerHTML); + + // Combine user message with quoted content for the full email body + const combined = ` +
+ ${contentEditableRef.current.innerHTML} +
+ ${quotedContent} + `; + + setComposeBody(combined); + } + }; + + // Handle sending with combined content + const handleSendWithCombinedContent = async () => { + // For rich editor mode, ensure we combine user message with quoted content + if (useRichEditor) { + // Create the final combined email body + const finalBody = ` +
+ ${userMessage} +
+ ${quotedContent} + `; + + // Set the complete body and send after a brief delay to ensure state is updated + setComposeBody(finalBody); + + // Small delay to ensure state update completes + setTimeout(() => { + handleSend(); + }, 50); + } else { + // For normal textarea mode, just use the existing handler + handleSend(); } }; @@ -295,21 +341,48 @@ export default function ComposeEmail({ {useRichEditor ? ( -
+
+ {/* User input area - completely separate from quoted content */} +
+ {!userMessage &&

Write your message here...

} +
+ + {/* Original email content - completely isolated */} + {quotedContent && ( +
+
+
+ )} +
) : (