From c3284982b5e93bf61aa0f5448bd5773c68eb7e31 Mon Sep 17 00:00:00 2001 From: alma Date: Sun, 27 Apr 2025 12:25:46 +0200 Subject: [PATCH] courrier refactor rebuild 2 --- components/email/ComposeEmail.tsx | 181 ++++++++---------------------- node_modules/.package-lock.json | 6 - package-lock.json | 7 -- yarn.lock | 5 - 4 files changed, 44 insertions(+), 155 deletions(-) diff --git a/components/email/ComposeEmail.tsx b/components/email/ComposeEmail.tsx index 1c77745c..bc470d59 100644 --- a/components/email/ComposeEmail.tsx +++ b/components/email/ComposeEmail.tsx @@ -181,40 +181,8 @@ export default function ComposeEmail(props: ComposeEmailAllProps) { const subject = subjectBase.match(/^Re:/i) ? subjectBase : `Re: ${subjectBase}`; setSubject(subject); - // Format the reply content with the quoted message included directly - const content = initialEmail.content || initialEmail.html || initialEmail.text || ''; - const sender = initialEmail.from && initialEmail.from.length > 0 - ? initialEmail.from[0].name || initialEmail.from[0].address - : 'Unknown sender'; - const date = initialEmail.date ? - (typeof initialEmail.date === 'string' ? new Date(initialEmail.date) : initialEmail.date) : - new Date(); - - // Format date for display - const formattedDate = date.toLocaleString('en-US', { - weekday: 'short', - year: 'numeric', - month: 'short', - day: 'numeric', - hour: '2-digit', - minute: '2-digit' - }); - - // Create reply content with quote - const replyContent = ` -

-

-

-

-
On ${formattedDate}, ${sender} wrote:
-
-
- ${content} -
-
- `; - - setEmailContent(replyContent); + // Initialize with empty content - the QuotedEmailContent component will handle displaying the quoted message + setEmailContent('

'); // Show CC field if there are CC recipients if (initialEmail.cc && initialEmail.cc.length > 0) { @@ -227,47 +195,8 @@ export default function ComposeEmail(props: ComposeEmailAllProps) { const subject = subjectBase.match(/^(Fwd|FW|Forward):/i) ? subjectBase : `Fwd: ${subjectBase}`; setSubject(subject); - // Format the forward content with the original email included directly - const content = initialEmail.content || initialEmail.html || initialEmail.text || ''; - const fromString = formatEmailAddresses(initialEmail.from || []); - const toString = formatEmailAddresses(initialEmail.to || []); - const date = initialEmail.date ? - (typeof initialEmail.date === 'string' ? new Date(initialEmail.date) : initialEmail.date) : - new Date(); - - // Format date for display - const formattedDate = date.toLocaleString('en-US', { - weekday: 'short', - year: 'numeric', - month: 'short', - day: 'numeric', - hour: '2-digit', - minute: '2-digit' - }); - - // Create forwarded content - const forwardContent = ` -

-

-

-

-
-
-
-
---------- Forwarded message ---------
-
From: ${fromString}
-
Date: ${formattedDate}
-
Subject: ${initialEmail.subject || ''}
-
To: ${toString}
-
- -
-
- `; - - setEmailContent(forwardContent); + // Initialize with empty content - the QuotedEmailContent component will handle displaying the forwarded message + setEmailContent('

'); // If the original email has attachments, we should include them if (initialEmail.attachments && initialEmail.attachments.length > 0) { @@ -461,6 +390,14 @@ export default function ComposeEmail(props: ComposeEmailAllProps) { maxHeight="none" preserveFormatting={true} /> + + {/* Render quoted content for replies and forwards */} + {initialEmail && type !== 'new' && ( + + )} @@ -599,72 +536,15 @@ function LegacyAdapter({ const type = determineType(); if (type === 'reply' || type === 'reply-all') { - // For reply, format with sender info and original content - const content = originalEmail?.content || ''; - const sender = replyTo?.name || replyTo?.email || 'Unknown sender'; - const date = new Date().toLocaleString('en-US', { - weekday: 'short', - year: 'numeric', - month: 'short', - day: 'numeric', - hour: '2-digit', - minute: '2-digit' - }); - - const replyContent = ` -

-

-

-

-
On ${date}, ${sender} wrote:
-
-
- ${content} -
-
- `; - - setComposeBody(replyContent); + // For reply, just set an empty div + setComposeBody('

'); } else if (type === 'forward') { - // For forward, format with original message details - const content = originalEmail?.content || ''; - const fromString = forwardFrom?.name || forwardFrom?.email || 'Unknown'; - const toString = 'Recipients'; - const date = new Date().toLocaleString('en-US', { - weekday: 'short', - year: 'numeric', - month: 'short', - day: 'numeric', - hour: '2-digit', - minute: '2-digit' - }); - - const forwardContent = ` -

-

-

-

-
-
-
-
---------- Forwarded message ---------
-
From: ${fromString}
-
Date: ${date}
-
Subject: ${composeSubject || ''}
-
To: ${toString}
-
- -
-
- `; - - setComposeBody(forwardContent); + // For forward, just set an empty div + setComposeBody('

'); } } - }, [originalEmail, replyTo, forwardFrom, composeBody, determineType, composeSubject]); + }, [originalEmail, replyTo, forwardFrom, composeBody, determineType, setComposeBody]); // Converts attachments to the expected format const convertAttachments = () => { @@ -824,6 +704,33 @@ function LegacyAdapter({ maxHeight="none" preserveFormatting={true} /> + + {/* Render original message for replies and forwards */} + {(originalEmail || replyTo || forwardFrom) && ( +
+ {replyTo ? ( + + ) : forwardFrom ? ( + + ) : null} +
+ )} diff --git a/node_modules/.package-lock.json b/node_modules/.package-lock.json index 96cab6b8..30baeaec 100644 --- a/node_modules/.package-lock.json +++ b/node_modules/.package-lock.json @@ -5622,12 +5622,6 @@ "npm": ">=8.2.3" } }, - "node_modules/quill-better-table": { - "version": "1.2.10", - "resolved": "https://registry.npmjs.org/quill-better-table/-/quill-better-table-1.2.10.tgz", - "integrity": "sha512-CFwxAQzt4EPCQuynQ65R/FU7Yu//kcDBb/rmBBOsFfO758+q50zvG/PDt4Lenv9DcrSgwnyNkfo4yeA5fzzVYQ==", - "license": "MIT" - }, "node_modules/quill-delta": { "version": "5.1.0", "resolved": "https://registry.npmjs.org/quill-delta/-/quill-delta-5.1.0.tgz", diff --git a/package-lock.json b/package-lock.json index d6154382..8a783762 100644 --- a/package-lock.json +++ b/package-lock.json @@ -71,7 +71,6 @@ "nodemailer": "^6.10.1", "pg": "^8.14.1", "quill": "^2.0.3", - "quill-better-table": "^1.2.10", "react": "^18", "react-datepicker": "^8.3.0", "react-day-picker": "8.10.1", @@ -6593,12 +6592,6 @@ "npm": ">=8.2.3" } }, - "node_modules/quill-better-table": { - "version": "1.2.10", - "resolved": "https://registry.npmjs.org/quill-better-table/-/quill-better-table-1.2.10.tgz", - "integrity": "sha512-CFwxAQzt4EPCQuynQ65R/FU7Yu//kcDBb/rmBBOsFfO758+q50zvG/PDt4Lenv9DcrSgwnyNkfo4yeA5fzzVYQ==", - "license": "MIT" - }, "node_modules/quill-delta": { "version": "5.1.0", "resolved": "https://registry.npmjs.org/quill-delta/-/quill-delta-5.1.0.tgz", diff --git a/yarn.lock b/yarn.lock index 6dff5e8a..5f586e7f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3031,11 +3031,6 @@ quick-format-unescaped@^4.0.3: resolved "https://registry.npmjs.org/quick-format-unescaped/-/quick-format-unescaped-4.0.4.tgz" integrity sha512-tYC1Q1hgyRuHgloV/YXs2w15unPVh8qfu/qCTfhTYamaw7fyhumKa2yGpdSo87vY32rIclj+4fWYQXUMs9EHvg== -quill-better-table@^1.2.10: - version "1.2.10" - resolved "https://registry.npmjs.org/quill-better-table/-/quill-better-table-1.2.10.tgz" - integrity sha512-CFwxAQzt4EPCQuynQ65R/FU7Yu//kcDBb/rmBBOsFfO758+q50zvG/PDt4Lenv9DcrSgwnyNkfo4yeA5fzzVYQ== - quill-delta@^5.1.0: version "5.1.0" resolved "https://registry.npmjs.org/quill-delta/-/quill-delta-5.1.0.tgz"