courrier multi account restore compose

This commit is contained in:
alma 2025-04-28 18:36:59 +02:00
parent 793e6c738b
commit df1570395d

View File

@ -164,7 +164,6 @@ export default function CourrierPage() {
// Email accounts for the sidebar // Email accounts for the sidebar
const [accounts, setAccounts] = useState<Account[]>([ const [accounts, setAccounts] = useState<Account[]>([
{ id: 'all-accounts', name: 'All', email: '', color: 'bg-gray-500', folders: [] },
{ id: 'loading-account', name: 'Loading...', email: '', color: 'bg-blue-500', folders: [] } { id: 'loading-account', name: 'Loading...', email: '', color: 'bg-blue-500', folders: [] }
]); ]);
const [selectedAccount, setSelectedAccount] = useState<Account | null>(null); const [selectedAccount, setSelectedAccount] = useState<Account | null>(null);
@ -222,7 +221,7 @@ export default function CourrierPage() {
// Initialize counts for all accounts and folders // Initialize counts for all accounts and folders
accounts.forEach(account => { accounts.forEach(account => {
if (account.id !== 'all-accounts' && account.id !== 'loading-account') { if (account.id !== 'loading-account') {
const folderCounts = new Map<string, number>(); const folderCounts = new Map<string, number>();
account.folders.forEach(folder => { account.folders.forEach(folder => {
folderCounts.set(folder, 0); folderCounts.set(folder, 0);
@ -247,7 +246,7 @@ export default function CourrierPage() {
}); });
// Update the unread count for the selected account and folder // Update the unread count for the selected account and folder
if (selectedAccount && selectedAccount.id !== 'all-accounts') { if (selectedAccount && selectedAccount.id !== 'loading-account') {
const folderCounts = accountFolderUnreadCounts.get(selectedAccount.id); const folderCounts = accountFolderUnreadCounts.get(selectedAccount.id);
if (folderCounts) { if (folderCounts) {
setUnreadCount(folderCounts.get(currentFolder) || 0); setUnreadCount(folderCounts.get(currentFolder) || 0);
@ -255,7 +254,7 @@ export default function CourrierPage() {
setUnreadCount(0); setUnreadCount(0);
} }
} else { } else {
// For 'all-accounts', sum up all unread counts for the current folder // For 'loading-account', sum up all unread counts for the current folder
let totalUnread = 0; let totalUnread = 0;
accountFolderUnreadCounts.forEach((folderCounts: Map<string, number>) => { accountFolderUnreadCounts.forEach((folderCounts: Map<string, number>) => {
totalUnread += folderCounts.get(currentFolder) || 0; totalUnread += folderCounts.get(currentFolder) || 0;
@ -280,7 +279,6 @@ export default function CourrierPage() {
if (!accounts || accounts.length === 0) { if (!accounts || accounts.length === 0) {
console.warn('Accounts array is empty, restoring defaults'); console.warn('Accounts array is empty, restoring defaults');
setAccounts([ setAccounts([
{ id: 'all-accounts', name: 'All', email: '', color: 'bg-gray-500', folders: mailboxes },
{ id: 'loading-account', name: 'Loading...', email: '', color: 'bg-blue-500', folders: mailboxes } { id: 'loading-account', name: 'Loading...', email: '', color: 'bg-blue-500', folders: mailboxes }
]); ]);
} }
@ -363,7 +361,7 @@ export default function CourrierPage() {
console.log('Session initialized, prefetch status:', data.prefetchStarted ? 'running' : 'not started'); console.log('Session initialized, prefetch status:', data.prefetchStarted ? 'running' : 'not started');
setPrefetchStarted(Boolean(data.prefetchStarted)); setPrefetchStarted(Boolean(data.prefetchStarted));
let updatedAccounts: Account[] = [{ id: 'all-accounts', name: 'All', email: '', color: 'bg-gray-500', folders: [] }]; let updatedAccounts: Account[] = [];
// Check if we have multiple accounts returned // Check if we have multiple accounts returned
if (data.allAccounts && Array.isArray(data.allAccounts) && data.allAccounts.length > 0) { if (data.allAccounts && Array.isArray(data.allAccounts) && data.allAccounts.length > 0) {
@ -595,7 +593,7 @@ export default function CourrierPage() {
// Update handleMailboxChange to properly handle per-account folders // Update handleMailboxChange to properly handle per-account folders
const handleMailboxChange = (folder: string, accountId?: string) => { const handleMailboxChange = (folder: string, accountId?: string) => {
if (accountId && accountId !== 'all-accounts') { if (accountId && accountId !== 'loading-account') {
const account = accounts.find(a => a.id === accountId); const account = accounts.find(a => a.id === accountId);
if (!account) { if (!account) {
@ -728,7 +726,7 @@ export default function CourrierPage() {
const handleAccountSelect = (account: Account) => { const handleAccountSelect = (account: Account) => {
setSelectedAccount(account); setSelectedAccount(account);
setShowFolders(true); setShowFolders(true);
if (account.id !== 'all-accounts') { if (account.id !== 'loading-account') {
setExpandedAccounts(prev => ({ setExpandedAccounts(prev => ({
...prev, ...prev,
[account.id]: true [account.id]: true
@ -1049,7 +1047,7 @@ export default function CourrierPage() {
<div className={`w-3 h-3 rounded-full ${account.color?.startsWith('#') ? 'bg-blue-500' : account.color || 'bg-blue-500'} mr-2`}></div> <div className={`w-3 h-3 rounded-full ${account.color?.startsWith('#') ? 'bg-blue-500' : account.color || 'bg-blue-500'} mr-2`}></div>
<span className="truncate text-gray-700 flex-1">{account.name}</span> <span className="truncate text-gray-700 flex-1">{account.name}</span>
{/* More options button */} {/* More options button */}
{account.id !== 'all-accounts' && ( {account.id !== 'loading-account' && (
<DropdownMenu> <DropdownMenu>
<DropdownMenuTrigger asChild> <DropdownMenuTrigger asChild>
<button type="button" className="ml-1 h-5 w-5 p-0 text-gray-400 hover:text-gray-600 flex items-center justify-center" onClick={e => e.stopPropagation()}> <button type="button" className="ml-1 h-5 w-5 p-0 text-gray-400 hover:text-gray-600 flex items-center justify-center" onClick={e => e.stopPropagation()}>
@ -1062,7 +1060,7 @@ export default function CourrierPage() {
</DropdownMenuContent> </DropdownMenuContent>
</DropdownMenu> </DropdownMenu>
)} )}
{account.id !== 'all-accounts' && ( {account.id !== 'loading-account' && (
<button <button
type="button" type="button"
className="ml-1 text-gray-400 hover:text-gray-600 cursor-pointer flex items-center justify-center h-5 w-5" className="ml-1 text-gray-400 hover:text-gray-600 cursor-pointer flex items-center justify-center h-5 w-5"
@ -1077,7 +1075,7 @@ export default function CourrierPage() {
{(() => { {(() => {
const isExpanded = expandedAccounts[account.id]; const isExpanded = expandedAccounts[account.id];
const hasFolders = account.folders && account.folders.length > 0; const hasFolders = account.folders && account.folders.length > 0;
return isExpanded && account.id !== 'all-accounts' && hasFolders && ( return isExpanded && account.id !== 'loading-account' && hasFolders && (
<div className="pl-4"> <div className="pl-4">
{account.folders.map((folder) => renderFolderButton(folder, account.id))} {account.folders.map((folder) => renderFolderButton(folder, account.id))}
</div> </div>