From 7276ca886195bfb3f6a7055f418a3712a874f8a3 Mon Sep 17 00:00:00 2001 From: alma Date: Sun, 27 Apr 2025 16:58:01 +0200 Subject: [PATCH] courrier multi account --- app/courrier/page.tsx | 112 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 102 insertions(+), 10 deletions(-) diff --git a/app/courrier/page.tsx b/app/courrier/page.tsx index 25d5576b..89531ae5 100644 --- a/app/courrier/page.tsx +++ b/app/courrier/page.tsx @@ -64,8 +64,8 @@ function SimplifiedLoadingFix() { ); } -interface SidebarAccount { - id: number | string; +interface Account { + id: number; name: string; email: string; color: string; @@ -119,11 +119,11 @@ export default function CourrierPage() { const [showAddAccountForm, setShowAddAccountForm] = useState(false); // Email accounts for the sidebar - const [accounts, setAccounts] = useState([ + const [accounts, setAccounts] = useState([ { id: 0, name: 'All', email: '', color: 'bg-gray-500' }, { id: 1, name: 'Loading...', email: '', color: 'bg-blue-500', folders: mailboxes } ]); - const [selectedAccount, setSelectedAccount] = useState(null); + const [selectedAccount, setSelectedAccount] = useState(null); // Update account folders when mailboxes change useEffect(() => { @@ -148,10 +148,8 @@ export default function CourrierPage() { // Example: counting unread emails in the inbox const unreadInInbox = (emails || []).filter(email => { // Access the 'read' property safely, handling both old and new email formats - // Use type assertion to avoid TypeScript errors - const emailAny = email as any; - return (!emailAny.read && emailAny.read !== undefined) || - (emailAny.flags && !emailAny.flags.seen) || + return (!email.read && email.read !== undefined) || + (email.flags && !email.flags.seen) || false; }).filter(email => currentFolder === 'INBOX').length; setUnreadCount(unreadInInbox); @@ -222,7 +220,7 @@ export default function CourrierPage() { console.log('Multiple accounts found:', data.allAccounts.length); // Add each account from the server - data.allAccounts.forEach((account: { id?: string | number, email: string, display_name?: string, color?: string }, index: number) => { + data.allAccounts.forEach((account, index) => { console.log(`[DEBUG] Processing account: ${account.email}, display_name: ${account.display_name}, has folders: ${!!data.mailboxes}`); const accountWithFolders = { @@ -791,4 +789,98 @@ export default function CourrierPage() { variant="ghost" className={`w-full justify-start text-sm py-1 px-2 ${ currentView === 'starred' ? 'bg-gray-100 text-gray-900' : 'text-gray-600 hover:text-gray-900' - }` \ No newline at end of file + }`} + onClick={() => handleMailboxChange('starred')} + > +
+ + Starred +
+ + + + + + + {/* Email List and Content View */} +
+ {/* Email List */} + + + {/* Email Content View */} +
+ {selectedEmail ? ( + handleEmailSelect('')} + onReply={handleReply} + onReplyAll={handleReplyAll} + onForward={handleForward} + onToggleStar={() => toggleStarred(selectedEmail.id)} + /> + ) : ( +
+ +

Select an email to read

+

+ Choose an email from the list or compose a new message to get started. +

+ +
+ )} +
+
+ + + + + {/* Login needed alert */} + setShowLoginNeeded(false)} + /> + + {/* Compose Modal */} + {showComposeModal && ( + setShowComposeModal(false)} + onSend={async (emailData: EmailData) => { + await sendEmail(emailData); + }} + /> + )} + + {/* Delete Confirmation Dialog */} + setShowDeleteConfirm(false)} + /> + + ); +} \ No newline at end of file