diff --git a/app/mail/page.tsx b/app/mail/page.tsx index 4b8a831..5bb3013 100644 --- a/app/mail/page.tsx +++ b/app/mail/page.tsx @@ -430,13 +430,13 @@ function cleanEmailContent(content: string): string { }); } -// Add a type for the available views -type MailView = 'inbox' | 'sent' | 'trash' | 'spam' | 'drafts' | 'archives' | 'archive' | 'starred'; +// First, let's define our mail view types based on the actual IMAP folders +type MailView = 'INBOX' | 'Sent' | 'Trash' | 'Spam' | 'Drafts' | 'Archives' | 'Archive' | 'starred'; -// Update the sidebar navigation +// Update the sidebar navigation to use exact IMAP folder names const sidebarNavItems = [ { - view: 'inbox' as MailView, + view: 'INBOX' as MailView, // Exact IMAP folder name label: 'Inbox', icon: Inbox, folder: 'INBOX' @@ -445,34 +445,34 @@ const sidebarNavItems = [ view: 'starred' as MailView, label: 'Starred', icon: Star, - folder: null // This is handled by the starred flag + folder: null // Special case for starred items }, { - view: 'sent' as MailView, + view: 'Sent' as MailView, // Exact IMAP folder name label: 'Sent', icon: Send, folder: 'Sent' }, { - view: 'drafts' as MailView, + view: 'Drafts' as MailView, // Exact IMAP folder name label: 'Drafts', icon: Edit, folder: 'Drafts' }, { - view: 'spam' as MailView, + view: 'Spam' as MailView, // Exact IMAP folder name label: 'Spam', icon: AlertOctagon, folder: 'Spam' }, { - view: 'trash' as MailView, + view: 'Trash' as MailView, // Exact IMAP folder name label: 'Trash', icon: Trash, folder: 'Trash' }, { - view: 'archives' as MailView, + view: 'Archives' as MailView, // Exact IMAP folder name label: 'Archives', icon: Archive, folder: 'Archives' @@ -487,7 +487,7 @@ export default function MailPage() { { id: 1, name: 'Mail', email: 'alma@governance-labs.org', color: 'bg-blue-500' } ]); const [selectedAccount, setSelectedAccount] = useState(null); - const [currentView, setCurrentView] = useState('inbox'); + const [currentView, setCurrentView] = useState('INBOX'); // Use exact IMAP folder name const [showCompose, setShowCompose] = useState(false); const [showDeleteConfirm, setShowDeleteConfirm] = useState(false); const [selectedEmails, setSelectedEmails] = useState([]); @@ -526,7 +526,7 @@ export default function MailPage() { console.log('Selected account:', selectedAccount); }, [emails, currentView, selectedAccount]); - // Update the filteredEmails logic to match exactly with the folders + // Update the filteredEmails logic to use exact folder names const filteredEmails = useMemo(() => { console.log('Filtering emails:', { total: emails.length, @@ -537,18 +537,12 @@ export default function MailPage() { currentView }); - // Find the current nav item - const currentNavItem = sidebarNavItems.find(item => item.view === currentView); - - // If it's starred view, filter by starred flag if (currentView === 'starred') { return emails.filter(email => email.starred); } - - // Otherwise filter by folder - return emails.filter(email => { - return email.folder === currentNavItem?.folder; - }); + + // For all other views, use exact folder name matching + return emails.filter(email => email.folder === currentView); }, [emails, currentView]); // Move getSelectedEmail inside the component @@ -585,7 +579,7 @@ export default function MailPage() { checkCredentials(); }, [router]); - // Update the loadEmails function + // Update the loadEmails function to preserve exact folder names const loadEmails = async () => { try { setLoading(true); @@ -599,7 +593,7 @@ export default function MailPage() { const data = await response.json(); console.log('Raw email data:', data); - // Process the emails + // Process the emails, keeping exact folder names const processedEmails = data.emails.map((email: any) => ({ ...email, id: Number(email.id), @@ -610,13 +604,12 @@ export default function MailPage() { date: email.date || new Date().toISOString(), read: email.read || false, starred: email.starred || false, - folder: email.folder || 'INBOX', // Keep original folder name - draft: email.draft || false + folder: email.folder // Keep exact folder name from IMAP })); - // Update unread count for inbox + // Update unread count for INBOX (note the exact folder name) const unreadInboxEmails = processedEmails.filter( - email => !email.read && email.folder === 'INBOX' && !email.draft + email => !email.read && email.folder === 'INBOX' ).length; setUnreadCount(unreadInboxEmails); @@ -1040,7 +1033,7 @@ export default function MailPage() { {item.label} - {item.view === 'inbox' && unreadCount > 0 && ( + {item.view === 'INBOX' && unreadCount > 0 && ( {unreadCount} @@ -1174,10 +1167,10 @@ export default function MailPage() {

- {currentView === 'inbox' && 'No emails in inbox'} + {currentView === 'INBOX' && 'No emails in inbox'} {currentView === 'starred' && 'No starred emails'} - {currentView === 'sent' && 'No sent emails'} - {currentView === 'trash' && 'No emails in trash'} + {currentView === 'Sent' && 'No sent emails'} + {currentView === 'Trash' && 'No emails in trash'}

{/* Add debug info */}

@@ -1208,7 +1201,7 @@ export default function MailPage() { }} /> - {currentView === 'sent' ? email.to : (email.fromName || email.from)} + {currentView === 'Sent' ? email.to : (email.fromName || email.from)}