courrier multi account restore compose
This commit is contained in:
parent
22f693884e
commit
ed39772a28
@ -177,19 +177,23 @@ export default function CourrierPage() {
|
||||
}
|
||||
}, [accounts, selectedAccount, showFolders, currentFolder]);
|
||||
|
||||
// Calculate unread count for each account
|
||||
// Calculate unread count for each account and folder
|
||||
useEffect(() => {
|
||||
// Create a map to store unread counts per account
|
||||
const accountUnreadCounts = new Map<string, number>();
|
||||
// Create a map to store unread counts per account and folder
|
||||
const accountFolderUnreadCounts = new Map<string, Map<string, number>>();
|
||||
|
||||
// Initialize counts for all accounts
|
||||
// Initialize counts for all accounts and folders
|
||||
accounts.forEach(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 => {
|
||||
// Access the 'read' property safely, handling both old and new email formats
|
||||
const emailWithFlags = email as unknown as EmailWithFlags;
|
||||
@ -197,28 +201,43 @@ export default function CourrierPage() {
|
||||
(emailWithFlags.flags && !emailWithFlags.flags.seen) ||
|
||||
false;
|
||||
|
||||
// Count unread emails regardless of current folder
|
||||
if (isUnread) {
|
||||
// If email has an accountId, increment that account's count
|
||||
if (email.accountId) {
|
||||
const currentCount = accountUnreadCounts.get(email.accountId) || 0;
|
||||
accountUnreadCounts.set(email.accountId, currentCount + 1);
|
||||
// Count unread emails for the specific account and folder
|
||||
if (isUnread && email.accountId && email.folder) {
|
||||
const folderCounts = accountFolderUnreadCounts.get(email.accountId);
|
||||
if (folderCounts) {
|
||||
const currentCount = folderCounts.get(email.folder) || 0;
|
||||
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') {
|
||||
setUnreadCount(accountUnreadCounts.get(selectedAccount.id) || 0);
|
||||
const folderCounts = accountFolderUnreadCounts.get(selectedAccount.id);
|
||||
if (folderCounts) {
|
||||
setUnreadCount(folderCounts.get(currentFolder) || 0);
|
||||
} else {
|
||||
setUnreadCount(0);
|
||||
}
|
||||
} else {
|
||||
// For 'all-accounts', sum up all unread counts
|
||||
// For 'all-accounts', sum up all unread counts for the current folder
|
||||
let totalUnread = 0;
|
||||
accountUnreadCounts.forEach(count => {
|
||||
totalUnread += count;
|
||||
accountFolderUnreadCounts.forEach((folderCounts: Map<string, number>) => {
|
||||
totalUnread += folderCounts.get(currentFolder) || 0;
|
||||
});
|
||||
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
|
||||
useEffect(() => {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user