courrier correct panel 2 scroll up
This commit is contained in:
parent
1cc8db2d20
commit
cb5d974fea
@ -141,11 +141,21 @@ export default function CourrierPage() {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// Flag to prevent multiple initialization attempts
|
// Flag to prevent multiple initialization attempts
|
||||||
let isMounted = true;
|
let isMounted = true;
|
||||||
|
let initAttempted = false;
|
||||||
|
|
||||||
const initSession = async () => {
|
const initSession = async () => {
|
||||||
|
if (initAttempted) return;
|
||||||
|
initAttempted = true;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
setLoading(true);
|
||||||
|
|
||||||
// First check if Redis is ready before making API calls
|
// First check if Redis is ready before making API calls
|
||||||
const redisStatus = await fetch('/api/redis/status').then(res => res.json()).catch(() => null);
|
const redisStatus = await fetch('/api/redis/status')
|
||||||
|
.then(res => res.json())
|
||||||
|
.catch(() => ({ ready: false }));
|
||||||
|
|
||||||
|
if (!isMounted) return;
|
||||||
|
|
||||||
// Call the session API to check email credentials and start prefetching
|
// Call the session API to check email credentials and start prefetching
|
||||||
const response = await fetch('/api/courrier/session');
|
const response = await fetch('/api/courrier/session');
|
||||||
@ -153,29 +163,52 @@ export default function CourrierPage() {
|
|||||||
|
|
||||||
if (!isMounted) return;
|
if (!isMounted) return;
|
||||||
|
|
||||||
if (data.authenticated && data.hasEmailCredentials) {
|
if (data.authenticated) {
|
||||||
console.log('Session initialized, prefetching started');
|
if (data.hasEmailCredentials) {
|
||||||
setPrefetchStarted(true);
|
console.log('Session initialized, prefetch status:', data.prefetchStarted ? 'running' : 'not started');
|
||||||
|
setPrefetchStarted(Boolean(data.prefetchStarted));
|
||||||
|
|
||||||
// Preload first page of emails for faster initial rendering
|
// Preload first page of emails for faster initial rendering
|
||||||
if (session?.user?.id) {
|
if (session?.user?.id) {
|
||||||
loadEmails();
|
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);
|
||||||
}
|
}
|
||||||
} else if (data.authenticated && !data.hasEmailCredentials) {
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
// User is authenticated but doesn't have email credentials
|
// User is authenticated but doesn't have email credentials
|
||||||
setShowLoginNeeded(true);
|
setShowLoginNeeded(true);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error initializing session:', error);
|
console.error('Error initializing session:', error);
|
||||||
|
} finally {
|
||||||
|
if (isMounted) {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (session?.user?.id) {
|
||||||
initSession();
|
initSession();
|
||||||
|
}
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
isMounted = false;
|
isMounted = false;
|
||||||
};
|
};
|
||||||
}, [session?.user?.id, loadEmails]);
|
}, [session?.user?.id, loadEmails, currentFolder]);
|
||||||
|
|
||||||
// Helper to get folder icons
|
// Helper to get folder icons
|
||||||
const getFolderIcon = (folder: string) => {
|
const getFolderIcon = (folder: string) => {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user