fix: align shared account folders with primary folders #151
This commit is contained in:
@@ -18,7 +18,6 @@ import {
|
|||||||
ChevronDown,
|
ChevronDown,
|
||||||
Folder,
|
Folder,
|
||||||
FolderOpen,
|
FolderOpen,
|
||||||
Users,
|
|
||||||
User,
|
User,
|
||||||
Palmtree,
|
Palmtree,
|
||||||
Settings,
|
Settings,
|
||||||
@@ -59,10 +58,6 @@ interface SidebarProps {
|
|||||||
const getIconForMailbox = (role?: string, name?: string, hasChildren?: boolean, isExpanded?: boolean, isShared?: boolean, id?: string) => {
|
const getIconForMailbox = (role?: string, name?: string, hasChildren?: boolean, isExpanded?: boolean, isShared?: boolean, id?: string) => {
|
||||||
const lowerName = name?.toLowerCase() || "";
|
const lowerName = name?.toLowerCase() || "";
|
||||||
|
|
||||||
if (id === 'shared-folders-root') {
|
|
||||||
return isExpanded ? FolderOpen : Users;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (id?.startsWith('shared-account-')) {
|
if (id?.startsWith('shared-account-')) {
|
||||||
return isExpanded ? FolderOpen : User;
|
return isExpanded ? FolderOpen : User;
|
||||||
}
|
}
|
||||||
|
|||||||
+14
-40
@@ -257,7 +257,10 @@ export function buildMailboxTree(mailboxes: Mailbox[]): MailboxNode[] {
|
|||||||
`total own: ${ownMailboxes.length}, shared: ${sharedMailboxes.length}`
|
`total own: ${ownMailboxes.length}, shared: ${sharedMailboxes.length}`
|
||||||
);
|
);
|
||||||
|
|
||||||
// If we have shared mailboxes, create a virtual "Shared Folders" parent
|
// For each shared account, create a virtual top-level account node
|
||||||
|
// containing that account's mailboxes. This places shared accounts as
|
||||||
|
// peers of the primary account's folders rather than nesting them under
|
||||||
|
// a "Shared Folders" wrapper. (GitHub #151)
|
||||||
if (sharedMailboxes.length > 0) {
|
if (sharedMailboxes.length > 0) {
|
||||||
// Group shared mailboxes by account
|
// Group shared mailboxes by account
|
||||||
const accountGroups = new Map<string, Mailbox[]>();
|
const accountGroups = new Map<string, Mailbox[]>();
|
||||||
@@ -269,20 +272,16 @@ export function buildMailboxTree(mailboxes: Mailbox[]): MailboxNode[] {
|
|||||||
accountGroups.get(accountId)!.push(mb);
|
accountGroups.get(accountId)!.push(mb);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Create virtual nodes for each shared account
|
|
||||||
const sharedAccountNodes: MailboxNode[] = [];
|
|
||||||
|
|
||||||
accountGroups.forEach((accountMailboxes, accountId) => {
|
accountGroups.forEach((accountMailboxes, accountId) => {
|
||||||
// Create account nodes
|
// Create nodes for this account's mailboxes
|
||||||
const accountMailboxMap = new Map<string, MailboxNode>();
|
const accountMailboxMap = new Map<string, MailboxNode>();
|
||||||
const accountRootNodes: MailboxNode[] = [];
|
const accountRootNodes: MailboxNode[] = [];
|
||||||
|
|
||||||
// Create nodes for this account's mailboxes
|
|
||||||
accountMailboxes.forEach(mailbox => {
|
accountMailboxes.forEach(mailbox => {
|
||||||
accountMailboxMap.set(mailbox.id, {
|
accountMailboxMap.set(mailbox.id, {
|
||||||
...mailbox,
|
...mailbox,
|
||||||
children: [],
|
children: [],
|
||||||
depth: 2 // Account level is depth 1, these are depth 2
|
depth: 0,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -298,10 +297,13 @@ export function buildMailboxTree(mailboxes: Mailbox[]): MailboxNode[] {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Correctly calculate depths from account root level down
|
// Render the shared account's mailboxes flush with primary-account
|
||||||
recalculateDepths(accountRootNodes, 2);
|
// mailboxes (depth 0) so the indents line up. The virtual account
|
||||||
|
// node visually wraps them via its chevron/header rather than via
|
||||||
|
// an extra indent level. (GitHub #151)
|
||||||
|
recalculateDepths(accountRootNodes, 0);
|
||||||
|
|
||||||
// Create virtual account folder node
|
// Create virtual account folder node at top level (depth 0)
|
||||||
const accountName = accountMailboxes[0]?.accountName || accountId;
|
const accountName = accountMailboxes[0]?.accountName || accountId;
|
||||||
const accountNode: MailboxNode = {
|
const accountNode: MailboxNode = {
|
||||||
id: `shared-account-${accountId}`,
|
id: `shared-account-${accountId}`,
|
||||||
@@ -327,39 +329,11 @@ export function buildMailboxTree(mailboxes: Mailbox[]): MailboxNode[] {
|
|||||||
accountName: accountName,
|
accountName: accountName,
|
||||||
isShared: true,
|
isShared: true,
|
||||||
children: accountRootNodes,
|
children: accountRootNodes,
|
||||||
depth: 1,
|
depth: 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
sharedAccountNodes.push(accountNode);
|
rootMailboxes.push(accountNode);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Create virtual "Shared Folders" root node
|
|
||||||
const sharedFoldersNode: MailboxNode = {
|
|
||||||
id: 'shared-folders-root',
|
|
||||||
name: 'Shared Folders',
|
|
||||||
sortOrder: 999, // After all own folders
|
|
||||||
totalEmails: sharedMailboxes.reduce((sum, mb) => sum + mb.totalEmails, 0),
|
|
||||||
unreadEmails: sharedMailboxes.reduce((sum, mb) => sum + mb.unreadEmails, 0),
|
|
||||||
totalThreads: 0,
|
|
||||||
unreadThreads: 0,
|
|
||||||
myRights: {
|
|
||||||
mayReadItems: true,
|
|
||||||
mayAddItems: false,
|
|
||||||
mayRemoveItems: false,
|
|
||||||
maySetSeen: false,
|
|
||||||
maySetKeywords: false,
|
|
||||||
mayCreateChild: false,
|
|
||||||
mayRename: false,
|
|
||||||
mayDelete: false,
|
|
||||||
maySubmit: false,
|
|
||||||
},
|
|
||||||
isSubscribed: true,
|
|
||||||
isShared: true,
|
|
||||||
children: sharedAccountNodes,
|
|
||||||
depth: 0,
|
|
||||||
};
|
|
||||||
|
|
||||||
rootMailboxes.push(sharedFoldersNode);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Smart multi-level sorting
|
// Smart multi-level sorting
|
||||||
|
|||||||
Reference in New Issue
Block a user