courrier multi account restore compose
This commit is contained in:
parent
5d284682a7
commit
cc988b7b8c
@ -80,6 +80,12 @@ export const useCourrier = () => {
|
|||||||
const loadEmails = useCallback(async (isLoadMore = false, accountId?: string) => {
|
const loadEmails = useCallback(async (isLoadMore = false, accountId?: string) => {
|
||||||
if (!session?.user?.id) return;
|
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);
|
setIsLoading(true);
|
||||||
setError(null);
|
setError(null);
|
||||||
|
|
||||||
@ -98,8 +104,8 @@ export const useCourrier = () => {
|
|||||||
queryParams.set('search', searchQuery);
|
queryParams.set('search', searchQuery);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add accountId if provided
|
// Add accountId if provided and not 'loading-account'
|
||||||
if (accountId && accountId !== 'all-accounts') {
|
if (accountId && accountId !== 'all-accounts' && accountId !== 'loading-account') {
|
||||||
queryParams.set('accountId', accountId);
|
queryParams.set('accountId', accountId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,7 +116,7 @@ export const useCourrier = () => {
|
|||||||
currentRequestPage,
|
currentRequestPage,
|
||||||
perPage,
|
perPage,
|
||||||
100,
|
100,
|
||||||
accountId && accountId !== 'all-accounts' ? accountId : undefined
|
accountId && accountId !== 'all-accounts' && accountId !== 'loading-account' ? accountId : undefined
|
||||||
);
|
);
|
||||||
if (cachedEmails) {
|
if (cachedEmails) {
|
||||||
// Ensure cached data has emails array property
|
// Ensure cached data has emails array property
|
||||||
|
|||||||
@ -62,6 +62,12 @@ export async function getCachedEmailsWithTimeout(
|
|||||||
timeoutMs: number = 100,
|
timeoutMs: number = 100,
|
||||||
accountId?: string
|
accountId?: string
|
||||||
): Promise<any | null> {
|
): 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) => {
|
return new Promise((resolve) => {
|
||||||
const timeoutId = setTimeout(() => {
|
const timeoutId = setTimeout(() => {
|
||||||
console.log(`Cache access timeout for ${userId}:${folder}:${page}:${perPage}${accountId ? ` for account ${accountId}` : ''}`);
|
console.log(`Cache access timeout for ${userId}:${folder}:${page}:${perPage}${accountId ? ` for account ${accountId}` : ''}`);
|
||||||
@ -73,25 +79,7 @@ export async function getCachedEmailsWithTimeout(
|
|||||||
clearTimeout(timeoutId);
|
clearTimeout(timeoutId);
|
||||||
if (result) {
|
if (result) {
|
||||||
console.log(`Using cached data for ${userId}:${folder}:${page}:${perPage}${accountId ? ` for account ${accountId}` : ''}`);
|
console.log(`Using cached data for ${userId}:${folder}:${page}:${perPage}${accountId ? ` for account ${accountId}` : ''}`);
|
||||||
|
resolve(result);
|
||||||
// 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 {
|
} else {
|
||||||
resolve(null);
|
resolve(null);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user