mail page ui correction maj compose 20 bis 6
This commit is contained in:
parent
f3d57f218e
commit
ef2a171ab1
@ -476,50 +476,12 @@ export default function MailPage() {
|
||||
|
||||
// Update the filteredEmails logic
|
||||
const filteredEmails = useMemo(() => {
|
||||
console.log('Current view:', currentView);
|
||||
console.log('Filtering emails for view:', currentView);
|
||||
console.log('Total emails:', emails.length);
|
||||
|
||||
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 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('<a.tmiri@governance-labs.org>') // From address in angle brackets
|
||||
);
|
||||
|
||||
case 'starred':
|
||||
return (
|
||||
email.starred === true ||
|
||||
email.flags?.includes('\\Flagged') // Some IMAP servers use Flagged for starred
|
||||
);
|
||||
|
||||
case 'trash':
|
||||
return (
|
||||
email.deleted === true ||
|
||||
email.category === 'trash' ||
|
||||
email.flags?.includes('\\Deleted') // Check IMAP deleted flag
|
||||
);
|
||||
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}, [emails, currentView]);
|
||||
|
||||
// We don't need complex filtering anymore since we're fetching from the correct folder
|
||||
return emails;
|
||||
}, [emails]);
|
||||
|
||||
// Move getSelectedEmail inside the component
|
||||
const getSelectedEmail = () => {
|
||||
@ -555,21 +517,26 @@ export default function MailPage() {
|
||||
checkCredentials();
|
||||
}, [router]);
|
||||
|
||||
// Update the loadEmails function to properly process the email data
|
||||
// Update the loadEmails function to fetch emails from the correct folder
|
||||
const loadEmails = async () => {
|
||||
try {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
|
||||
const response = await fetch('/api/mail');
|
||||
// Determine which folder to fetch based on currentView
|
||||
const folder = currentView === 'sent' ? 'Sent' :
|
||||
currentView === 'trash' ? 'Trash' :
|
||||
currentView === 'starred' ? 'Starred' : 'INBOX';
|
||||
|
||||
const response = await fetch(`/api/mail?folder=${folder}`);
|
||||
if (!response.ok) {
|
||||
throw new Error('Failed to load emails');
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
console.log('Raw email data:', data);
|
||||
console.log(`Loading emails from ${folder} folder:`, data);
|
||||
|
||||
// Process the emails with better property handling
|
||||
// Process the emails
|
||||
const processedEmails = data.emails.map((email: any) => ({
|
||||
...email,
|
||||
id: Number(email.id),
|
||||
@ -578,18 +545,10 @@ export default function MailPage() {
|
||||
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
|
||||
folder: folder.toLowerCase(),
|
||||
read: email.read || false
|
||||
}));
|
||||
|
||||
console.log('Processed emails:', processedEmails);
|
||||
setEmails(processedEmails);
|
||||
} catch (err) {
|
||||
console.error('Error loading emails:', err);
|
||||
@ -599,7 +558,7 @@ export default function MailPage() {
|
||||
}
|
||||
};
|
||||
|
||||
// Update useEffect to load emails when view changes
|
||||
// Add an effect to reload emails when the view changes
|
||||
useEffect(() => {
|
||||
loadEmails();
|
||||
}, [currentView]);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user