diff --git a/components/email.tsx b/components/email.tsx index 39283d2..0ed2efd 100644 --- a/components/email.tsx +++ b/components/email.tsx @@ -228,32 +228,30 @@ export function Email() { items: notificationItems, }); - // Dispatch event for Outlook-style notifications (for new emails detected by ID) - if (hasNewEmails) { - // Get only the newly arrived emails (by ID comparison) - const newEmails = transformedEmails - .filter(e => newEmailIds.has(e.id) && !e.read) - .slice(0, 5); // Limit to 5 most recent new emails + // Dispatch event for Outlook-style notifications (for new emails detected by ID) + if (hasNewEmails) { + // Get only the newly arrived emails (by ID comparison) + const newEmails = transformedEmails + .filter(e => newEmailIds.has(e.id) && !e.read) + .slice(0, 5); // Limit to 5 most recent new emails + + if (newEmails.length > 0) { + console.log('[Email Widget] 📧 Dispatching new emails event', { + newEmailsCount: newEmails.length, + newEmailIds: Array.from(newEmailIds), + previousCount: lastUnreadCountRef.current, + currentCount: currentUnreadCount, + previousEmailIds: Array.from(lastEmailIdsRef.current), + }); - if (newEmails.length > 0) { - console.log('[Email Widget] 📧 Dispatching new emails event', { - newEmailsCount: newEmails.length, - newEmailIds: Array.from(newEmailIds), - previousCount, - currentCount: currentUnreadCount, - previousEmailIds: Array.from(lastEmailIdsRef.current), - }); - - window.dispatchEvent(new CustomEvent('new-emails-detected', { - detail: { - emails: transformedEmails, - accountMap: accountMap, - previousCount, - currentCount: currentUnreadCount, - } - })); + window.dispatchEvent(new CustomEvent('new-emails-detected', { + detail: { + emails: transformedEmails, + accountMap: accountMap, + previousCount: lastUnreadCountRef.current, + currentCount: currentUnreadCount, } - } + })); } }