mail page ui correction maj compose 20 bis 12

This commit is contained in:
alma 2025-04-16 14:25:03 +02:00
parent 12cd7de9bd
commit ca3d1d832b
2 changed files with 19 additions and 14 deletions

View File

@ -177,7 +177,7 @@ export async function GET() {
return;
}
// Sort results in reverse order (newest first) and take last 20
// Sort results to get the most recent messages first
const messageNumbers = results
.sort((a, b) => b - a)
.slice(0, 20);
@ -195,7 +195,7 @@ export async function GET() {
struct: true
});
f.on('message', (msg, seqno) => {
f.on('message', (msg) => {
const email: any = {
id: '',
from: '',
@ -205,7 +205,8 @@ export async function GET() {
starred: false,
body: '',
to: '',
folder: folderMap[folderName] || folderName.toLowerCase()
folder: folderName, // Keep the original folder name
draft: false
};
msg.on('body', (stream, info) => {
@ -234,12 +235,10 @@ export async function GET() {
});
msg.once('end', () => {
// Only add non-draft emails to INBOX
// Only add the email if it belongs in this folder
if (folderName === 'INBOX' && !email.draft) {
allEmails.push(email);
}
// Add all emails from other folders
else if (folderName !== 'INBOX') {
} else if (folderName !== 'INBOX') {
allEmails.push(email);
}
});

View File

@ -51,6 +51,7 @@ interface Email {
cc?: string;
bcc?: string;
flags?: string[];
draft?: boolean;
}
interface Attachment {
@ -477,12 +478,18 @@ export default function MailPage() {
// Update the filteredEmails logic
const filteredEmails = useMemo(() => {
console.log('Filtering emails:', {
total: emails.length,
folders: emails.map(e => e.folder),
currentView
});
return emails.filter(email => {
switch (currentView) {
case 'inbox':
return email.folder === 'INBOX';
return email.folder === 'INBOX' && !email.draft;
case 'starred':
return email.starred;
return Boolean(email.starred);
case 'sent':
return email.folder === 'Sent';
case 'trash':
@ -527,13 +534,12 @@ export default function MailPage() {
checkCredentials();
}, [router]);
// Update the loadEmails function to handle different folders correctly
// Update the loadEmails function
const loadEmails = async () => {
try {
setLoading(true);
setError(null);
// Fetch emails based on the current view
const response = await fetch('/api/mail');
if (!response.ok) {
throw new Error('Failed to load emails');
@ -553,13 +559,13 @@ export default function MailPage() {
date: email.date || new Date().toISOString(),
read: email.read || false,
starred: email.starred || false,
deleted: email.deleted || false,
folder: email.folder || 'inbox'
folder: email.folder || 'INBOX', // Keep original folder name
draft: email.draft || false
}));
// Update unread count for inbox
const unreadInboxEmails = processedEmails.filter(
email => !email.read && !email.deleted && email.folder === 'inbox'
email => !email.read && email.folder === 'INBOX' && !email.draft
).length;
setUnreadCount(unreadInboxEmails);