courrier formatting
This commit is contained in:
parent
029c0e44c9
commit
dc919c58a9
@ -645,7 +645,7 @@ export const useEmailState = () => {
|
|||||||
|
|
||||||
// Handle loading more emails
|
// Handle loading more emails
|
||||||
const handleLoadMore = useCallback(() => {
|
const handleLoadMore = useCallback(() => {
|
||||||
logEmailOp('LOAD_MORE', `Current state - page: ${state.page}, totalPages: ${state.totalPages}, isLoading: ${state.isLoading}`);
|
logEmailOp('LOAD_MORE', `Current state - page: ${state.page}, totalPages: ${state.totalPages}, isLoading: ${state.isLoading}, current emails: ${state.emails.length}`);
|
||||||
|
|
||||||
// Skip if we're already at the last page
|
// Skip if we're already at the last page
|
||||||
if (state.page >= state.totalPages) {
|
if (state.page >= state.totalPages) {
|
||||||
@ -666,10 +666,19 @@ export const useEmailState = () => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the trigger time and load more
|
// Update the trigger time
|
||||||
loadMoreTriggerTimeRef.current = now;
|
loadMoreTriggerTimeRef.current = now;
|
||||||
dispatch({ type: 'SET_PAGE', payload: state.page + 1 });
|
|
||||||
}, [state.page, state.totalPages, state.isLoading, logEmailOp, dispatch]);
|
// CRITICAL FIX: Set nextPage value and log for debugging
|
||||||
|
const nextPage = state.page + 1;
|
||||||
|
console.log(`[DEBUG-LOAD_MORE] Incrementing page from ${state.page} to ${nextPage}, current emails count: ${state.emails.length}`);
|
||||||
|
|
||||||
|
// Increment the page to trigger the useEffect
|
||||||
|
dispatch({ type: 'SET_PAGE', payload: nextPage });
|
||||||
|
|
||||||
|
// CRITICAL FIX: Force loading state to true immediately
|
||||||
|
dispatch({ type: 'SET_LOADING', payload: true });
|
||||||
|
}, [state.page, state.totalPages, state.isLoading, state.emails.length, logEmailOp, dispatch]);
|
||||||
|
|
||||||
// Effect to load emails when folder changes
|
// Effect to load emails when folder changes
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -679,10 +688,15 @@ export const useEmailState = () => {
|
|||||||
|
|
||||||
logEmailOp('FOLDER_CHANGE', `Loading emails for folder ${state.currentFolder} with account ${effectiveAccountId}`);
|
logEmailOp('FOLDER_CHANGE', `Loading emails for folder ${state.currentFolder} with account ${effectiveAccountId}`);
|
||||||
|
|
||||||
// Load emails with the correct account ID
|
// Reset page to 1 when changing folders
|
||||||
|
if (state.page !== 1) {
|
||||||
|
dispatch({ type: 'SET_PAGE', payload: 1 });
|
||||||
|
}
|
||||||
|
|
||||||
|
// Load emails with the correct account ID (not appending since this is a folder change)
|
||||||
loadEmails(false, effectiveAccountId);
|
loadEmails(false, effectiveAccountId);
|
||||||
}
|
}
|
||||||
}, [session?.user?.id, state.currentFolder, loadEmails, logEmailOp]);
|
}, [session?.user?.id, state.currentFolder, state.page, loadEmails, logEmailOp, dispatch]);
|
||||||
|
|
||||||
// Effect to load more emails when page changes
|
// Effect to load more emails when page changes
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -699,7 +713,7 @@ export const useEmailState = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Debug log
|
// Debug log
|
||||||
console.log(`[DEBUG-PAGE_EFFECT] Page effect running for page ${state.page}, lastLoaded=${lastPageLoadedRef.current}`);
|
console.log(`[DEBUG-PAGE_EFFECT] Page effect running for page ${state.page}, lastLoaded=${lastPageLoadedRef.current}, current emails count: ${state.emails.length}`);
|
||||||
|
|
||||||
// Skip if this page was already loaded
|
// Skip if this page was already loaded
|
||||||
if (lastPageLoadedRef.current === state.page) {
|
if (lastPageLoadedRef.current === state.page) {
|
||||||
@ -713,9 +727,9 @@ export const useEmailState = () => {
|
|||||||
// Extract account ID for consistency
|
// Extract account ID for consistency
|
||||||
const { effectiveAccountId } = normalizeFolderAndAccount(state.currentFolder);
|
const { effectiveAccountId } = normalizeFolderAndAccount(state.currentFolder);
|
||||||
|
|
||||||
logEmailOp('PAGINATION', `Loading page ${state.page} for ${state.currentFolder} with account ${effectiveAccountId}`);
|
logEmailOp('PAGINATION', `Loading more emails for page ${state.page} (total emails so far: ${state.emails.length})`);
|
||||||
|
|
||||||
// Load more emails with the correct account ID
|
// CRITICAL FIX: Always use isLoadMore=true when page > 1
|
||||||
loadEmails(true, effectiveAccountId);
|
loadEmails(true, effectiveAccountId);
|
||||||
|
|
||||||
// Reset the lastPageLoadedRef when folder changes or component unmounts
|
// Reset the lastPageLoadedRef when folder changes or component unmounts
|
||||||
@ -726,8 +740,8 @@ export const useEmailState = () => {
|
|||||||
prevFolderRef.current = state.currentFolder;
|
prevFolderRef.current = state.currentFolder;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
// Changed dependency array to exclude state.isLoading to prevent loop
|
// Do NOT include state.emails.length here to prevent infinite loops
|
||||||
}, [session?.user?.id, state.page, state.currentFolder, loadEmails, logEmailOp]);
|
}, [session?.user?.id, state.page, state.currentFolder, state.isLoading, loadEmails, logEmailOp]);
|
||||||
|
|
||||||
// Fetch unread counts from API
|
// Fetch unread counts from API
|
||||||
const fetchUnreadCounts = useCallback(async () => {
|
const fetchUnreadCounts = useCallback(async () => {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user