courrier multi account restore compose
This commit is contained in:
parent
c102b6e89b
commit
ccd8b8d762
@ -177,18 +177,47 @@ export default function CourrierPage() {
|
||||
}
|
||||
}, [accounts, selectedAccount, showFolders, currentFolder]);
|
||||
|
||||
// Calculate unread count (this would be replaced with actual data in production)
|
||||
// Calculate unread count for each account
|
||||
useEffect(() => {
|
||||
// Example: counting unread emails in the inbox
|
||||
const unreadInInbox = (emails || []).filter(email => {
|
||||
// Create a map to store unread counts per account
|
||||
const accountUnreadCounts = new Map<string, number>();
|
||||
|
||||
// Initialize counts for all accounts
|
||||
accounts.forEach(account => {
|
||||
if (account.id !== 'all-accounts' && account.id !== 'loading-account') {
|
||||
accountUnreadCounts.set(account.id, 0);
|
||||
}
|
||||
});
|
||||
|
||||
// Count unread emails for each account
|
||||
(emails || []).forEach(email => {
|
||||
// Access the 'read' property safely, handling both old and new email formats
|
||||
const emailWithFlags = email as unknown as EmailWithFlags;
|
||||
return (!emailWithFlags.read && emailWithFlags.read !== undefined) ||
|
||||
(emailWithFlags.flags && !emailWithFlags.flags.seen) ||
|
||||
false;
|
||||
}).filter(email => currentFolder === 'INBOX').length;
|
||||
setUnreadCount(unreadInInbox);
|
||||
}, [emails, currentFolder]);
|
||||
const isUnread = (!emailWithFlags.read && emailWithFlags.read !== undefined) ||
|
||||
(emailWithFlags.flags && !emailWithFlags.flags.seen) ||
|
||||
false;
|
||||
|
||||
if (isUnread && email.folder === 'INBOX') {
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Update the unread count for the selected account
|
||||
if (selectedAccount && selectedAccount.id !== 'all-accounts') {
|
||||
setUnreadCount(accountUnreadCounts.get(selectedAccount.id) || 0);
|
||||
} else {
|
||||
// For 'all-accounts', sum up all unread counts
|
||||
let totalUnread = 0;
|
||||
accountUnreadCounts.forEach(count => {
|
||||
totalUnread += count;
|
||||
});
|
||||
setUnreadCount(totalUnread);
|
||||
}
|
||||
}, [emails, selectedAccount, accounts]);
|
||||
|
||||
// Ensure accounts section is never empty
|
||||
useEffect(() => {
|
||||
|
||||
@ -25,6 +25,7 @@ export interface Email {
|
||||
folder: string;
|
||||
hasAttachments: boolean;
|
||||
contentFetched?: boolean;
|
||||
accountId?: string;
|
||||
}
|
||||
|
||||
export interface EmailListResult {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user