courrier multi account restore compose

This commit is contained in:
alma 2025-04-28 15:28:18 +02:00
parent 85efb768cf
commit f47596bd9f
2 changed files with 14 additions and 23 deletions

View File

@ -61,8 +61,7 @@ export async function GET(request: Request) {
folder,
page,
perPage,
searchQuery,
accountId
accountId || undefined
);
// The result is already cached in the getEmails function

View File

@ -81,23 +81,14 @@ 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);
// Keep reference to the current page for this request
const currentRequestPage = page;
try {
// Build query params
// Construct query parameters
const queryParams = new URLSearchParams({
folder: currentFolder,
page: currentRequestPage.toString(),
page: page.toString(),
perPage: perPage.toString()
});
@ -105,21 +96,22 @@ export const useCourrier = () => {
queryParams.set('search', searchQuery);
}
// Add accountId if provided and not 'loading-account'
if (accountId && accountId !== 'all-accounts' && accountId !== 'loading-account') {
// Add accountId to query params if provided
if (accountId) {
queryParams.set('accountId', accountId);
console.log(`Loading emails for account ${accountId} in folder ${currentFolder}`);
}
// First try Redis cache with low timeout
// Try to get cached emails first
const currentRequestPage = page;
const cachedEmails = await getCachedEmailsWithTimeout(
session.user.id,
currentFolder,
currentRequestPage,
perPage,
100,
session.user.id,
accountId || 'default',
currentFolder,
currentRequestPage,
perPage,
accountId && accountId !== 'all-accounts' && accountId !== 'loading-account' ? accountId : undefined
);
if (cachedEmails) {
// Ensure cached data has emails array property
if (Array.isArray(cachedEmails.emails)) {
@ -238,7 +230,7 @@ export const useCourrier = () => {
setSelectedEmailIds([]);
}
} catch (err) {
console.error(`Error loading emails for page ${currentRequestPage}:`, err);
console.error(`Error loading emails for page ${page}:`, err);
// Set emails to empty array on error to prevent runtime issues
if (!isLoadMore) {
setEmails([]);