mail page ui correction maj compose 20 bis 5
This commit is contained in:
parent
1712924bcf
commit
f3d57f218e
@ -50,6 +50,7 @@ interface Email {
|
|||||||
category?: 'inbox' | 'sent' | 'trash';
|
category?: 'inbox' | 'sent' | 'trash';
|
||||||
cc?: string;
|
cc?: string;
|
||||||
bcc?: string;
|
bcc?: string;
|
||||||
|
flags?: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Attachment {
|
interface Attachment {
|
||||||
@ -477,36 +478,48 @@ export default function MailPage() {
|
|||||||
const filteredEmails = useMemo(() => {
|
const filteredEmails = useMemo(() => {
|
||||||
console.log('Current view:', currentView);
|
console.log('Current view:', currentView);
|
||||||
console.log('Total emails:', emails.length);
|
console.log('Total emails:', emails.length);
|
||||||
console.log('Selected account:', selectedAccount);
|
|
||||||
|
|
||||||
return emails.filter(email => {
|
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) {
|
switch (currentView) {
|
||||||
case 'inbox':
|
case 'inbox':
|
||||||
return true; // Keep inbox as is since it's working
|
return true; // Keep inbox as is since it's working
|
||||||
|
|
||||||
case 'sent':
|
case 'sent':
|
||||||
// Check if the email is from our email address
|
// Check multiple conditions that might indicate a sent email
|
||||||
const userEmail = 'a.tmiri@governance-labs.org'; // This should match your email
|
return (
|
||||||
console.log('Checking sent email:', {
|
email.category === 'sent' || // Check if it's in the sent folder
|
||||||
from: email.from,
|
email.flags?.includes('\\Sent') || // Check IMAP sent flag
|
||||||
userEmail: userEmail,
|
email.from.toLowerCase() === 'a.tmiri@governance-labs.org' || // Direct from address match
|
||||||
isSent: email.from.includes(userEmail)
|
email.from.toLowerCase().includes('<a.tmiri@governance-labs.org>') // From address in angle brackets
|
||||||
});
|
);
|
||||||
return email.from.toLowerCase().includes(userEmail.toLowerCase());
|
|
||||||
|
|
||||||
case 'starred':
|
case 'starred':
|
||||||
// For starred emails, check if starred property exists and is true
|
return (
|
||||||
return email.starred === true;
|
email.starred === true ||
|
||||||
|
email.flags?.includes('\\Flagged') // Some IMAP servers use Flagged for starred
|
||||||
|
);
|
||||||
|
|
||||||
case 'trash':
|
case 'trash':
|
||||||
// For trash, check if deleted property exists and is true
|
return (
|
||||||
return email.deleted === true;
|
email.deleted === true ||
|
||||||
|
email.category === 'trash' ||
|
||||||
|
email.flags?.includes('\\Deleted') // Check IMAP deleted flag
|
||||||
|
);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}, [emails, currentView, selectedAccount]);
|
}, [emails, currentView]);
|
||||||
|
|
||||||
// Move getSelectedEmail inside the component
|
// Move getSelectedEmail inside the component
|
||||||
const getSelectedEmail = () => {
|
const getSelectedEmail = () => {
|
||||||
@ -542,7 +555,7 @@ export default function MailPage() {
|
|||||||
checkCredentials();
|
checkCredentials();
|
||||||
}, [router]);
|
}, [router]);
|
||||||
|
|
||||||
// Update the loadEmails function to ensure we set default values
|
// Update the loadEmails function to properly process the email data
|
||||||
const loadEmails = async () => {
|
const loadEmails = async () => {
|
||||||
try {
|
try {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
@ -556,15 +569,24 @@ export default function MailPage() {
|
|||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
console.log('Raw email data:', data);
|
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) => ({
|
const processedEmails = data.emails.map((email: any) => ({
|
||||||
...email,
|
...email,
|
||||||
id: Number(email.id),
|
id: Number(email.id),
|
||||||
// Set default values for optional properties
|
from: email.from || '',
|
||||||
starred: email.starred || false,
|
to: email.to || '',
|
||||||
deleted: email.deleted || false,
|
subject: email.subject || '(No subject)',
|
||||||
category: email.category || 'inbox',
|
body: email.body || '',
|
||||||
read: email.read || false
|
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);
|
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 (
|
||||||
|
<div className="fixed bottom-4 right-4 bg-black/80 text-white p-4 rounded-lg text-xs">
|
||||||
|
<div>Current view: {currentView}</div>
|
||||||
|
<div>Total emails: {emails.length}</div>
|
||||||
|
<div>Filtered emails: {filteredEmails.length}</div>
|
||||||
|
<div>Categories present: {
|
||||||
|
[...new Set(emails.map(e => e.category))].join(', ')
|
||||||
|
}</div>
|
||||||
|
<div>Flags present: {
|
||||||
|
[...new Set(emails.flatMap(e => e.flags || []))].join(', ')
|
||||||
|
}</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
return (
|
return (
|
||||||
<div className="flex h-[calc(100vh-theme(spacing.12))] items-center justify-center bg-gray-100 mt-12">
|
<div className="flex h-[calc(100vh-theme(spacing.12))] items-center justify-center bg-gray-100 mt-12">
|
||||||
@ -1484,6 +1525,9 @@ export default function MailPage() {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{/* Add debug info in development */}
|
||||||
|
<DebugInfo />
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user