diff --git a/app/courrier/page.tsx b/app/courrier/page.tsx index 3cf9bfbd..c8da2b8a 100644 --- a/app/courrier/page.tsx +++ b/app/courrier/page.tsx @@ -391,31 +391,31 @@ export default function CourrierPage() { // Update accounts state setAccounts(updatedAccounts); console.log('[DEBUG] Updated accounts:', updatedAccounts); + + // Auto-select the first non-All account if available + if (updatedAccounts.length > 1) { + console.log('Auto-selecting account:', updatedAccounts[1]); + setSelectedAccount(updatedAccounts[1]); + setShowFolders(true); + + // Ensure folders are visible for the selected account + setExpandedAccounts(prev => ({ + ...prev, + [updatedAccounts[1].id]: true + })); + + // Set initial selected folder + setSelectedFolders(prev => ({ + ...prev, + [updatedAccounts[1].id]: 'INBOX' + })); + } } else { // User is authenticated but doesn't have email credentials setShowLoginNeeded(true); } } - // Auto-select the first non-All account if available - if (updatedAccounts.length > 1) { - console.log('Auto-selecting account:', updatedAccounts[1]); - setSelectedAccount(updatedAccounts[1]); - setShowFolders(true); - - // Ensure folders are visible for the selected account - setExpandedAccounts(prev => ({ - ...prev, - [updatedAccounts[1].id]: true - })); - - // Set initial selected folder - setSelectedFolders(prev => ({ - ...prev, - [updatedAccounts[1].id]: 'INBOX' - })); - } - // Preload first page of emails for faster initial rendering if (session?.user?.id) { await loadEmails();