From 84713f463041916667de2f8f5a2814b0d0fd8a5e Mon Sep 17 00:00:00 2001 From: alma Date: Fri, 25 Apr 2025 19:13:24 +0200 Subject: [PATCH] panel 2 courier api restore --- app/courrier/page.tsx | 128 ++++++++++++++++++++++++++++++------------ 1 file changed, 91 insertions(+), 37 deletions(-) diff --git a/app/courrier/page.tsx b/app/courrier/page.tsx index a162fd3e..17aa6fc4 100644 --- a/app/courrier/page.tsx +++ b/app/courrier/page.tsx @@ -456,7 +456,7 @@ export default function CourrierPage() { const [searchQuery, setSearchQuery] = useState(''); const [mobileSidebarOpen, setMobileSidebarOpen] = useState(false); const [composeOpen, setComposeOpen] = useState(false); - const [accountsDropdownOpen, setAccountsDropdownOpen] = useState(false); + const [accountsDropdownOpen, setAccountsDropdownOpen] = useState(true); const [foldersDropdownOpen, setFoldersDropdownOpen] = useState(false); const [showAccountActions, setShowAccountActions] = useState(null); const [showEmailActions, setShowEmailActions] = useState(false); @@ -566,17 +566,27 @@ export default function CourrierPage() { const data = await emailResponse.json(); console.log(`Loaded ${data.emails?.length || 0} emails`); + console.log('API response data:', { + emailCount: data.emails?.length || 0, + folderCount: data.folders?.length || 0 + }); // Set available folders if present if (data.folders) { + console.log('Setting folders from initialization:', data.folders); setAvailableFolders(data.folders); // Update the mail account with folders - setAccounts(prev => prev.map(account => - account.id === 1 - ? { ...account, folders: data.folders } - : account - )); + setAccounts(prev => { + console.log('Updating accounts with folders'); + return prev.map(account => + account.id === 1 + ? { ...account, folders: data.folders } + : account + ); + }); + } else { + console.warn('No folders returned from API during initialization'); } // Process emails and sort by date @@ -861,22 +871,25 @@ export default function CourrierPage() { ) : filteredEmails.length === 0 ? (
- -

+ +

{searchQuery ? 'No emails match your search' : 'No emails in this folder'}

{error && (

{error}

)} -

Folder: {currentView}

-

Total emails: {emails.length}

+

Folder: {currentView}

+

Total emails: {emails.length}

) : ( @@ -1445,9 +1458,12 @@ export default function CourrierPage() { try { // Skip if already loading if (isLoadingInitial || isLoadingMore) { + console.log('Skipping loadEmails - already loading'); return; } + console.log(`Loading emails for folder: ${currentView}, page: ${page}, isLoadMore: ${isLoadMore}`); + if (isLoadMore) { setIsLoadingMore(true); } else { @@ -1462,14 +1478,31 @@ export default function CourrierPage() { ); if (!response.ok) { + console.error('API response error:', response.status, response.statusText); throw new Error('Failed to load emails'); } const data = await response.json(); + console.log('API response:', { + emailCount: data.emails?.length || 0, + folderCount: data.folders?.length || 0, + hasMore: data.hasMore, + total: data.total + }); // Set available folders if (data.folders) { + console.log('Setting available folders:', data.folders); setAvailableFolders(data.folders); + + // Update the mail account with folders + setAccounts(prev => prev.map(account => + account.id === 1 + ? { ...account, folders: data.folders } + : account + )); + } else { + console.warn('No folders returned from API'); } // Process and sort emails @@ -1643,36 +1676,57 @@ export default function CourrierPage() { {/* Show folders for email accounts (not for "All" account) */} - {account.id !== 0 && account.folders && account.folders.length > 0 && ( -
-
- Folders -
- {account.folders.map((folder) => ( + {account.id !== 0 && ( +
+
+ Folders - ))} +
+ {account.folders && account.folders.length > 0 ? ( + account.folders.map((folder) => ( + + )) + ) : ( +
+
+ + Loading folders... +
+
+ )}
)}