diff --git a/app/courrier/page.tsx b/app/courrier/page.tsx index 00968686..408ce776 100644 --- a/app/courrier/page.tsx +++ b/app/courrier/page.tsx @@ -245,7 +245,6 @@ export default function CourrierPage() { console.log('allAccounts is array:', Array.isArray(data.allAccounts)); console.log('allAccounts length:', data.allAccounts?.length || 0); - // Inspect each account's structure if (data.authenticated) { if (data.hasEmailCredentials) { console.log('Session initialized, prefetch status:', data.prefetchStarted ? 'running' : 'not started'); @@ -330,25 +329,25 @@ export default function CourrierPage() { console.log('Auto-selecting account:', updatedAccounts[1]); setSelectedAccount(updatedAccounts[1]); setShowFolders(true); + + // Load emails for the selected account + if (session?.user?.id) { + await loadEmails(); + } } - // Preload first page of emails for faster initial rendering - if (session?.user?.id) { - await loadEmails(); - - // If the user hasn't opened this page recently, trigger a background refresh - if (data.lastVisit && Date.now() - data.lastVisit > 5 * 60 * 1000) { - // It's been more than 5 minutes, refresh in background - try { - const refreshResponse = await fetch('/api/courrier/refresh', { - method: 'POST', - headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ folder: currentFolder }) - }); - console.log('Background refresh triggered'); - } catch (error) { - console.error('Failed to trigger background refresh', error); - } + // If the user hasn't opened this page recently, trigger a background refresh + if (data.lastVisit && Date.now() - data.lastVisit > 5 * 60 * 1000) { + // It's been more than 5 minutes, refresh in background + try { + const refreshResponse = await fetch('/api/courrier/refresh', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ folder: currentFolder }) + }); + console.log('Background refresh triggered'); + } catch (error) { + console.error('Failed to trigger background refresh', error); } } } else {