From f3d57f218e498c34563eda4b41b6946f0df316b7 Mon Sep 17 00:00:00 2001 From: alma Date: Wed, 16 Apr 2025 14:04:22 +0200 Subject: [PATCH] mail page ui correction maj compose 20 bis 5 --- app/mail/page.tsx | 86 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 65 insertions(+), 21 deletions(-) diff --git a/app/mail/page.tsx b/app/mail/page.tsx index 9608ef1..9e9e27f 100644 --- a/app/mail/page.tsx +++ b/app/mail/page.tsx @@ -50,6 +50,7 @@ interface Email { category?: 'inbox' | 'sent' | 'trash'; cc?: string; bcc?: string; + flags?: string[]; } interface Attachment { @@ -477,36 +478,48 @@ export default function MailPage() { const filteredEmails = useMemo(() => { console.log('Current view:', currentView); console.log('Total emails:', emails.length); - console.log('Selected account:', selectedAccount); return emails.filter(email => { + // Log the email properties for debugging + console.log('Processing email:', { + id: email.id, + from: email.from, + to: email.to, + folder: email.category, + flags: email.flags // Some IMAP servers use flags to mark sent items + }); + switch (currentView) { case 'inbox': return true; // Keep inbox as is since it's working case 'sent': - // Check if the email is from our email address - const userEmail = 'a.tmiri@governance-labs.org'; // This should match your email - console.log('Checking sent email:', { - from: email.from, - userEmail: userEmail, - isSent: email.from.includes(userEmail) - }); - return email.from.toLowerCase().includes(userEmail.toLowerCase()); + // Check multiple conditions that might indicate a sent email + return ( + email.category === 'sent' || // Check if it's in the sent folder + email.flags?.includes('\\Sent') || // Check IMAP sent flag + email.from.toLowerCase() === 'a.tmiri@governance-labs.org' || // Direct from address match + email.from.toLowerCase().includes('') // From address in angle brackets + ); case 'starred': - // For starred emails, check if starred property exists and is true - return email.starred === true; + return ( + email.starred === true || + email.flags?.includes('\\Flagged') // Some IMAP servers use Flagged for starred + ); case 'trash': - // For trash, check if deleted property exists and is true - return email.deleted === true; + return ( + email.deleted === true || + email.category === 'trash' || + email.flags?.includes('\\Deleted') // Check IMAP deleted flag + ); default: return true; } }); - }, [emails, currentView, selectedAccount]); + }, [emails, currentView]); // Move getSelectedEmail inside the component const getSelectedEmail = () => { @@ -542,7 +555,7 @@ export default function MailPage() { checkCredentials(); }, [router]); - // Update the loadEmails function to ensure we set default values + // Update the loadEmails function to properly process the email data const loadEmails = async () => { try { setLoading(true); @@ -556,15 +569,24 @@ export default function MailPage() { const data = await response.json(); console.log('Raw email data:', data); - // Process the emails and ensure default values are set + // Process the emails with better property handling const processedEmails = data.emails.map((email: any) => ({ ...email, id: Number(email.id), - // Set default values for optional properties - starred: email.starred || false, - deleted: email.deleted || false, - category: email.category || 'inbox', - read: email.read || false + from: email.from || '', + to: email.to || '', + subject: email.subject || '(No subject)', + body: email.body || '', + date: email.date || new Date().toISOString(), + // Try to determine the category/folder + category: email.category || + (email.folder?.toLowerCase() === 'sent' ? 'sent' : 'inbox'), + // Process flags if they exist + flags: Array.isArray(email.flags) ? email.flags : [], + // Set other properties with defaults + starred: email.starred || email.flags?.includes('\\Flagged') || false, + deleted: email.deleted || email.flags?.includes('\\Deleted') || false, + read: email.read || email.flags?.includes('\\Seen') || false })); console.log('Processed emails:', processedEmails); @@ -948,6 +970,25 @@ export default function MailPage() { } }; + // Add this debug component to help us see what's happening + const DebugInfo = () => { + if (process.env.NODE_ENV !== 'development') return null; + + return ( +
+
Current view: {currentView}
+
Total emails: {emails.length}
+
Filtered emails: {filteredEmails.length}
+
Categories present: { + [...new Set(emails.map(e => e.category))].join(', ') + }
+
Flags present: { + [...new Set(emails.flatMap(e => e.flags || []))].join(', ') + }
+
+ ); + }; + if (error) { return (
@@ -1484,6 +1525,9 @@ export default function MailPage() {
)} + + {/* Add debug info in development */} + ); } \ No newline at end of file