1 import type { ReactNode } from 'react';
2 import { useEffect, useState } from 'react';
4 import { AppsDropdown, Sidebar, SidebarDrawerItems, SidebarNav } from '@proton/components';
5 import SidebarStorageUpsell from '@proton/components/containers/payments/subscription/SidebarStorageUpsell';
6 import useDisplayContactsWidget from '@proton/components/hooks/useDisplayContactsWidget';
7 import useEffectOnce from '@proton/hooks/useEffectOnce';
8 import { APPS } from '@proton/shared/lib/constants';
10 import { useActiveShare } from '../../../../hooks/drive/useActiveShare';
11 import { useDebug } from '../../../../hooks/drive/useDebug';
12 import type { ShareWithKey } from '../../../../store';
13 import { useDefaultShare } from '../../../../store';
14 import { useCreateDevice } from '../../../../store/_shares/useCreateDevice';
15 import { useCreatePhotos } from '../../../../store/_shares/useCreatePhotos';
16 import { logPerformanceMarker } from '../../../../utils/performance';
17 import DriveSidebarFooter from './DriveSidebarFooter';
18 import DriveSidebarList from './DriveSidebarList';
21 isHeaderExpanded: boolean;
22 toggleHeaderExpanded: () => void;
27 const DriveSidebar = ({ logo, primary, isHeaderExpanded, toggleHeaderExpanded }: Props) => {
28 const { activeShareId } = useActiveShare();
29 const { getDefaultShare } = useDefaultShare();
30 const debug = useDebug();
32 const [defaultShare, setDefaultShare] = useState<ShareWithKey>();
33 const { createDevice } = useCreateDevice();
34 const { createPhotosShare } = useCreatePhotos();
37 logPerformanceMarker('drive_performance_clicktonavrendered_histogram');
40 void getDefaultShare().then(setDefaultShare);
41 }, [getDefaultShare]);
43 const displayContactsInHeader = useDisplayContactsWidget();
46 * The sidebar supports multiple shares, but as we currently have
47 * only one main share in use, we gonna use the default share only,
48 * unless the opposite is decided.
50 const shares = defaultShare ? [defaultShare] : [];
53 app={APPS.PROTONDRIVE}
54 appsDropdown={<AppsDropdown app={APPS.PROTONDRIVE} />}
56 expanded={isHeaderExpanded}
57 onToggleExpand={toggleHeaderExpanded}
59 version={<DriveSidebarFooter />}
61 postFooter={<SidebarStorageUpsell app={APPS.PROTONDRIVE} />}
65 <DriveSidebarList shareId={activeShareId} userShares={shares} />
66 {displayContactsInHeader && <SidebarDrawerItems toggleHeaderDropdown={toggleHeaderExpanded} />}
69 {debug ? <button onClick={createDevice}>Create device</button> : null}
70 {debug ? <button onClick={createPhotosShare}>Create photos</button> : null}
75 export default DriveSidebar;