diff --git a/app/courrier/page.tsx b/app/courrier/page.tsx index b61e1297..00968686 100644 --- a/app/courrier/page.tsx +++ b/app/courrier/page.tsx @@ -125,8 +125,7 @@ export default function CourrierPage() { // Email accounts for the sidebar const [accounts, setAccounts] = useState([ - { id: 'all-accounts', name: 'All', email: '', color: 'bg-gray-500' }, - { id: 'loading-account', name: 'Loading...', email: '', color: 'bg-blue-500', folders: [] } + { id: 'all-accounts', name: 'All', email: '', color: 'bg-gray-500' } ]); const [selectedAccount, setSelectedAccount] = useState(null); @@ -137,17 +136,16 @@ export default function CourrierPage() { useEffect(() => { console.log('Mailboxes updated:', mailboxes); setAccounts(prev => { - const updated = [...prev]; - if (updated.length > 1) { - // Only update folders, preserve other properties including ID - if (updated[1]) { - updated[1] = { - ...updated[1], - folders: mailboxes - }; - } - console.log('Updated accounts with new mailboxes:', updated); + // Keep the "All" account and update the actual email account + const updated = [prev[0]]; // Keep the "All" account + if (prev.length > 1) { + // Update the existing email account + updated.push({ + ...prev[1], + folders: mailboxes + }); } + console.log('Updated accounts with new mailboxes:', updated); return updated; }); }, [mailboxes]); @@ -196,11 +194,10 @@ export default function CourrierPage() { if (!accounts || accounts.length === 0) { console.warn('Accounts array is empty, restoring defaults'); setAccounts([ - { id: 'all-accounts', name: 'All', email: '', color: 'bg-gray-500' }, - { id: 'loading-account', name: 'Loading...', email: '', color: 'bg-blue-500', folders: mailboxes } + { id: 'all-accounts', name: 'All', email: '', color: 'bg-gray-500' } ]); } - }, [accounts, mailboxes]); + }, [accounts]); // Initialize session and start prefetching useEffect(() => {