From 795211f785012f8f3d02c7a585aec0e528ae1dfa Mon Sep 17 00:00:00 2001 From: alma Date: Mon, 21 Apr 2025 22:13:07 +0200 Subject: [PATCH] mail page fix design dang --- app/courrier/page.tsx | 4 +- components/ComposeEmail.tsx | 108 +++++++++++++++++++++--------------- 2 files changed, 65 insertions(+), 47 deletions(-) diff --git a/app/courrier/page.tsx b/app/courrier/page.tsx index ed935087..0ccd8a2a 100644 --- a/app/courrier/page.tsx +++ b/app/courrier/page.tsx @@ -41,7 +41,7 @@ import { import DOMPurify from 'isomorphic-dompurify'; import ComposeEmail from '@/components/ComposeEmail'; -interface Account { +export interface Account { id: number; name: string; email: string; @@ -49,7 +49,7 @@ interface Account { folders?: string[]; } -interface Email { +export interface Email { id: number; accountId: number; from: string; diff --git a/components/ComposeEmail.tsx b/components/ComposeEmail.tsx index 2a7af66e..28d74f50 100644 --- a/components/ComposeEmail.tsx +++ b/components/ComposeEmail.tsx @@ -7,6 +7,7 @@ import { Label } from '@/components/ui/label'; import { Paperclip, X } from 'lucide-react'; import { Textarea } from '@/components/ui/textarea'; import { decodeComposeContent, encodeComposeContent } from '@/lib/compose-mime-decoder'; +import { Email } from '@/app/courrier/page'; interface ComposeEmailProps { showCompose: boolean; @@ -32,6 +33,16 @@ interface ComposeEmailProps { content: string; type: 'reply' | 'reply-all' | 'forward'; }; + onSend: (email: Email) => void; + onCancel: () => void; + onBodyChange?: (body: string) => void; + initialTo?: string; + initialSubject?: string; + initialBody?: string; + initialCc?: string; + initialBcc?: string; + replyTo?: Email; + forwardFrom?: Email; } export default function ComposeEmail({ @@ -54,68 +65,75 @@ export default function ComposeEmail({ attachments, setAttachments, handleSend, - originalEmail + originalEmail, + onSend, + onCancel, + onBodyChange, + initialTo, + initialSubject, + initialBody, + initialCc, + initialBcc, + replyTo, + forwardFrom }: ComposeEmailProps) { const composeBodyRef = useRef(null); const [localContent, setLocalContent] = useState(''); useEffect(() => { if (composeBodyRef.current) { - // Only initialize once when empty or first loading - if (!composeBody || composeBody.trim() === '') { - // Simple structure with one area for new text and one for original - composeBodyRef.current.innerHTML = ` -
-
- ${composeBody ? decodeComposeContent(composeBody) : ''} -
- `; - - // 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); - } - } else { - // For existing content, just update the original email part - const originalEmailDiv = composeBodyRef.current.querySelector('#original-email'); - if (originalEmailDiv) { - originalEmailDiv.innerHTML = decodeComposeContent(composeBody); - } + // Initialize the content structure + const originalContent = originalEmail?.content || ''; + composeBodyRef.current.innerHTML = ` +
+
+ ${originalContent} +
+ `; + + // 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); } } - }, []); // Only run once on initial mount, not on every composeBody change + }, [originalEmail]); // Run when originalEmail changes // Modified input handler to prevent nested structures const handleInput = (e: React.FormEvent) => { - // Get raw content from the editable div - const currentContent = e.currentTarget.innerHTML; - - // Store the original content reference - const originalEmailDiv = e.currentTarget.querySelector('#original-email'); - const originalContent = originalEmailDiv?.innerHTML || ''; - - // Extract user-typed content (everything before original-email div) - const userContent = currentContent.split('
+ ${newReplyContent} +
${originalContent}
`; - - // Update the compose body - setComposeBody(combinedContent); + + // Update the compose form + if (onBodyChange) { + onBodyChange(formattedContent); + } }; const handleFileAttachment = async (e: React.ChangeEvent) => {