From fb0ab726758d66030a850dfaf2d95f8df1159da7 Mon Sep 17 00:00:00 2001 From: alma Date: Sat, 26 Apr 2025 21:12:18 +0200 Subject: [PATCH] courrier clean 2$ --- components/ComposeEmail.tsx | 136 ++++++++++++++---------------------- 1 file changed, 54 insertions(+), 82 deletions(-) diff --git a/components/ComposeEmail.tsx b/components/ComposeEmail.tsx index d207721d..d02800ad 100644 --- a/components/ComposeEmail.tsx +++ b/components/ComposeEmail.tsx @@ -6,33 +6,21 @@ import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { Textarea } from '@/components/ui/textarea'; import { Label } from '@/components/ui/label'; -import DOMPurify from 'isomorphic-dompurify'; +import { sanitizeHtml } from '@/lib/utils/email-formatter'; -// Add a CSS style block to handle the direction properly -const forceLTRStyles = ` -.force-ltr { - direction: ltr !important; - text-align: left !important; - unicode-bidi: isolate !important; - writing-mode: horizontal-tb !important; -} -.force-ltr * { - direction: ltr !important; - text-align: left !important; - unicode-bidi: isolate !important; -} -[dir="rtl"] .force-ltr, -[dir="rtl"] .force-ltr * { - direction: ltr !important; - text-align: left !important; -} +// Simple CSS for email styling - leverages our centralized sanitization for text direction +const emailStyles = ` .email-content { - direction: ltr !important; - text-align: left !important; + font-family: Arial, sans-serif; } -.email-content * { - direction: ltr !important; - text-align: left !important; +.quoted-content { + margin-top: 20px; + border-top: 1px solid #e2e2e2; + padding-top: 10px; + color: #555; +} +.user-message { + margin-bottom: 20px; } `; @@ -164,17 +152,19 @@ export default function ComposeEmail({ // Handle contentEditable input changes const handleUserMessageChange = () => { if (contentEditableRef.current) { - const content = contentEditableRef.current.innerHTML; + let content = contentEditableRef.current.innerHTML; // Check if this is the initial state or if the user has actually typed something if (content && content !== '

Write your message here...

') { setHasStartedTyping(true); } + // Sanitize the user's message using our centralized sanitizer + content = sanitizeHtml(content); setUserMessage(content); // Combine user message with quoted content for the full email body - const combined = `${content}${quotedContent ? `
${quotedContent}
` : ''}`; + const combined = `${content}${quotedContent ? `
${quotedContent}
` : ''}`; setComposeBody(combined); } }; @@ -188,10 +178,12 @@ export default function ComposeEmail({ // For rich editor, combine user message with quoted content if (useRichEditor) { - // Wrap the content with proper direction styles - const userContent = userMessage ? `
${userMessage}
` : ''; - const quotedWithStyles = quotedContent ? `
${quotedContent}
` : ''; - const combinedContent = `${userContent}${quotedWithStyles}`; + // Wrap the content with appropriate styling + const userContent = userMessage ? `
${userMessage}
` : ''; + const quotedWithStyles = quotedContent ? `
${quotedContent}
` : ''; + + // Use our centralized sanitizer to ensure proper direction + const combinedContent = sanitizeHtml(`${userContent}${quotedWithStyles}`); setComposeBody(combinedContent); @@ -235,7 +227,7 @@ export default function ComposeEmail({ {showCompose && (
{/* Add global styles for email direction */} -