diff --git a/app/api/courrier/session/route.ts b/app/api/courrier/session/route.ts index 73227d91..d1f2ce42 100644 --- a/app/api/courrier/session/route.ts +++ b/app/api/courrier/session/route.ts @@ -155,7 +155,8 @@ export async function GET() { id: account.id, email: account.email, display_name: account.display_name || account.email, - color: account.color || "#0082c9" + color: account.color || "#0082c9", + folders: cachedSession?.mailboxes || [] // Add folders directly to each account })) }); } catch (dbError) { diff --git a/app/courrier/page.tsx b/app/courrier/page.tsx index 89531ae5..ab19b427 100644 --- a/app/courrier/page.tsx +++ b/app/courrier/page.tsx @@ -143,6 +143,14 @@ export default function CourrierPage() { console.log('Current accounts state:', accounts); }, [accounts]); + // Debug selectedAccount state + useEffect(() => { + console.log('Selected account changed:', selectedAccount); + if (selectedAccount) { + console.log('Selected account folders:', selectedAccount.folders); + } + }, [selectedAccount]); + // Calculate unread count (this would be replaced with actual data in production) useEffect(() => { // Example: counting unread emails in the inbox @@ -249,6 +257,13 @@ export default function CourrierPage() { console.log('Setting accounts:', updatedAccounts); setAccounts(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); + } + // Preload first page of emails for faster initial rendering if (session?.user?.id) { await loadEmails(); @@ -741,8 +756,10 @@ export default function CourrierPage() { - {/* Show folders for this account if it's selected and folders are shown */} - {selectedAccount?.id === account.id && showFolders && account.folders && ( + {/* Show folders for this account if it's selected and folders are shown + OR if it's the first account and no account is selected */} + {((selectedAccount?.id === account.id && showFolders) || + (!selectedAccount && account.id !== 0 && account.folders)) && (