courrier multi account restore compose

This commit is contained in:
alma 2025-04-28 14:55:29 +02:00
parent 22f693884e
commit ed39772a28

View File

@ -177,19 +177,23 @@ export default function CourrierPage() {
} }
}, [accounts, selectedAccount, showFolders, currentFolder]); }, [accounts, selectedAccount, showFolders, currentFolder]);
// Calculate unread count for each account // Calculate unread count for each account and folder
useEffect(() => { useEffect(() => {
// Create a map to store unread counts per account // Create a map to store unread counts per account and folder
const accountUnreadCounts = new Map<string, number>(); const accountFolderUnreadCounts = new Map<string, Map<string, number>>();
// Initialize counts for all accounts // Initialize counts for all accounts and folders
accounts.forEach(account => { accounts.forEach(account => {
if (account.id !== 'all-accounts' && account.id !== 'loading-account') { if (account.id !== 'all-accounts' && account.id !== 'loading-account') {
accountUnreadCounts.set(account.id, 0); const folderCounts = new Map<string, number>();
account.folders.forEach(folder => {
folderCounts.set(folder, 0);
});
accountFolderUnreadCounts.set(account.id, folderCounts);
} }
}); });
// Count unread emails for each account // Count unread emails for each account and folder
(emails || []).forEach(email => { (emails || []).forEach(email => {
// Access the 'read' property safely, handling both old and new email formats // Access the 'read' property safely, handling both old and new email formats
const emailWithFlags = email as unknown as EmailWithFlags; const emailWithFlags = email as unknown as EmailWithFlags;
@ -197,28 +201,43 @@ export default function CourrierPage() {
(emailWithFlags.flags && !emailWithFlags.flags.seen) || (emailWithFlags.flags && !emailWithFlags.flags.seen) ||
false; false;
// Count unread emails regardless of current folder // Count unread emails for the specific account and folder
if (isUnread) { if (isUnread && email.accountId && email.folder) {
// If email has an accountId, increment that account's count const folderCounts = accountFolderUnreadCounts.get(email.accountId);
if (email.accountId) { if (folderCounts) {
const currentCount = accountUnreadCounts.get(email.accountId) || 0; const currentCount = folderCounts.get(email.folder) || 0;
accountUnreadCounts.set(email.accountId, currentCount + 1); folderCounts.set(email.folder, currentCount + 1);
} }
} }
}); });
// Update the unread count for the selected account // Update the unread count for the selected account and folder
if (selectedAccount && selectedAccount.id !== 'all-accounts') { if (selectedAccount && selectedAccount.id !== 'all-accounts') {
setUnreadCount(accountUnreadCounts.get(selectedAccount.id) || 0); const folderCounts = accountFolderUnreadCounts.get(selectedAccount.id);
if (folderCounts) {
setUnreadCount(folderCounts.get(currentFolder) || 0);
} else {
setUnreadCount(0);
}
} else { } else {
// For 'all-accounts', sum up all unread counts // For 'all-accounts', sum up all unread counts for the current folder
let totalUnread = 0; let totalUnread = 0;
accountUnreadCounts.forEach(count => { accountFolderUnreadCounts.forEach((folderCounts: Map<string, number>) => {
totalUnread += count; totalUnread += folderCounts.get(currentFolder) || 0;
}); });
setUnreadCount(totalUnread); setUnreadCount(totalUnread);
} }
}, [emails, selectedAccount, accounts]);
// Log the counts for debugging
console.log('Unread counts per account and folder:',
Object.fromEntries(
Array.from(accountFolderUnreadCounts.entries()).map(([accountId, folderCounts]) => [
accountId,
Object.fromEntries(folderCounts.entries())
])
)
);
}, [emails, selectedAccount, currentFolder, accounts]);
// Ensure accounts section is never empty // Ensure accounts section is never empty
useEffect(() => { useEffect(() => {