courrier multi account restore compose

This commit is contained in:
alma 2025-04-28 13:18:48 +02:00
parent 5d284682a7
commit cc988b7b8c
2 changed files with 16 additions and 22 deletions

View File

@ -80,6 +80,12 @@ export const useCourrier = () => {
const loadEmails = useCallback(async (isLoadMore = false, accountId?: string) => {
if (!session?.user?.id) return;
// Skip loading if accountId is 'loading-account'
if (accountId === 'loading-account') {
console.log('Skipping email load for loading account');
return;
}
setIsLoading(true);
setError(null);
@ -98,8 +104,8 @@ export const useCourrier = () => {
queryParams.set('search', searchQuery);
}
// Add accountId if provided
if (accountId && accountId !== 'all-accounts') {
// Add accountId if provided and not 'loading-account'
if (accountId && accountId !== 'all-accounts' && accountId !== 'loading-account') {
queryParams.set('accountId', accountId);
}
@ -110,7 +116,7 @@ export const useCourrier = () => {
currentRequestPage,
perPage,
100,
accountId && accountId !== 'all-accounts' ? accountId : undefined
accountId && accountId !== 'all-accounts' && accountId !== 'loading-account' ? accountId : undefined
);
if (cachedEmails) {
// Ensure cached data has emails array property

View File

@ -62,6 +62,12 @@ export async function getCachedEmailsWithTimeout(
timeoutMs: number = 100,
accountId?: string
): Promise<any | null> {
// Skip cache if accountId is 'loading-account'
if (accountId === 'loading-account') {
console.log(`Skipping cache for loading account`);
return null;
}
return new Promise((resolve) => {
const timeoutId = setTimeout(() => {
console.log(`Cache access timeout for ${userId}:${folder}:${page}:${perPage}${accountId ? ` for account ${accountId}` : ''}`);
@ -73,25 +79,7 @@ export async function getCachedEmailsWithTimeout(
clearTimeout(timeoutId);
if (result) {
console.log(`Using cached data for ${userId}:${folder}:${page}:${perPage}${accountId ? ` for account ${accountId}` : ''}`);
// Validate and normalize the data structure
if (typeof result === 'object') {
// Make sure we have an emails array
if (!result.emails && Array.isArray(result)) {
// If result is an array, convert to proper structure
resolve({ emails: result });
} else if (!result.emails) {
// If no emails property, add empty array
resolve({ ...result, emails: [] });
} else {
// Normal case, return as is
resolve(result);
}
} else {
// Invalid data, return null
console.warn('Invalid cached data format:', result);
resolve(null);
}
} else {
resolve(null);
}