courrier multi account restore compose

This commit is contained in:
alma 2025-04-28 12:14:20 +02:00
parent d683458213
commit f1adfca1d9

View File

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