1 import type { ReactNode } from 'react';
2 import { memo } from 'react';
3 import * as React from 'react';
5 import { c } from 'ttag';
7 import type { Folder, FolderWithSubFolders } from '@proton/shared/lib/interfaces/Folder';
9 import { getUnreadCount } from '../../helpers/sidebar';
10 import type { ApplyLabelsParams } from '../../hooks/actions/label/useApplyLabels';
11 import type { MoveParams } from '../../hooks/actions/move/useMoveToFolder';
12 import type { UnreadCounts } from './MailSidebarList';
13 import SidebarFolder from './SidebarFolder';
16 currentLabelID: string;
17 counterMap: UnreadCounts;
19 loadingFolders: boolean;
20 updateFocusItem: (item: string) => void;
21 handleToggleFolder: (folder: Folder, expanded: boolean) => void;
22 foldersTreeview: FolderWithSubFolders[];
23 moveToFolder: (params: MoveParams) => void;
24 applyLabels: (params: ApplyLabelsParams) => void;
27 const SidebarFolders = ({
38 const onlyOneLevel = foldersTreeview.every((folder) => !folder.subfolders?.length);
39 const emptyFolders = !loadingFolders && !folders?.length;
41 const treeviewReducer = (acc: ReactNode[], folder: FolderWithSubFolders, level = 0): any[] => {
45 currentLabelID={currentLabelID}
49 onToggle={handleToggleFolder}
50 expanded={Boolean(folder.Expanded)}
51 unreadCount={getUnreadCount(counterMap, folder)}
53 onFocus={updateFocusItem}
54 treeMode={!onlyOneLevel}
55 moveToFolder={moveToFolder}
56 applyLabels={applyLabels}
60 if (folder.Expanded && Array.isArray(folder.subfolders) && folder.subfolders.length) {
61 folder.subfolders.forEach((folder: FolderWithSubFolders) => treeviewReducer(acc, folder, level + 1));
67 return emptyFolders ? (
68 <div className="py-2 ml-7 text-sm color-weak">{c('Description').t`No folders`}</div>
71 {foldersTreeview.reduce(
72 (acc: React.ReactNode[], folder: FolderWithSubFolders) => treeviewReducer(acc, folder),
79 export default memo(SidebarFolders);