1 import { useState } from 'react';
2 import { useLocation } from 'react-router-dom';
4 import { useUser } from '@proton/account/user/hooks';
6 CalendarDrawerAppButton,
7 ContactDrawerAppButton,
10 DrawerVisibilityButton,
13 QuickSettingsAppButton,
19 } from '@proton/components';
20 import { APPS } from '@proton/shared/lib/constants';
21 import { isAppInView } from '@proton/shared/lib/drawer/helpers';
22 import { DRAWER_NATIVE_APPS } from '@proton/shared/lib/drawer/interfaces';
23 import isTruthy from '@proton/utils/isTruthy';
25 import { useIsActiveLinkReadOnly } from '../../store/_views/utils';
26 import AppErrorBoundary from '../AppErrorBoundary';
27 import FileRecoveryBanner from '../ResolveLockedVolumes/LockedVolumesBanner';
28 import DriveQuickSettings from '../drawer/DriveQuickSettings';
29 import { DriveHeaderPrivate } from './DriveHeader';
30 import { getDriveDrawerPermissions } from './drawerPermissions';
31 import { ActionMenuButton } from './sidebar/ActionMenu/ActionMenuButton';
32 import DriveSidebar from './sidebar/DriveSidebar';
35 children?: JSX.Element | JSX.Element[];
38 const DriveWindow = ({ children }: Props) => {
39 const [user] = useUser();
40 const { state: expanded, toggle: toggleExpanded } = useToggle();
42 const [recoveryBannerVisible, setRecoveryBannerVisible] = useState(true);
44 const { isReadOnly } = useIsActiveLinkReadOnly();
46 useOpenDrawerOnLoad();
47 const { appInView, showDrawerSidebar } = useDrawer();
48 const location = useLocation();
50 const fileRecoveryBanner = recoveryBannerVisible ? (
53 setRecoveryBannerVisible(false);
58 const top = <TopBanners app={APPS.PROTONDRIVE}>{fileRecoveryBanner}</TopBanners>;
60 const drawerSettingsButton = (
61 <QuickSettingsAppButton aria-expanded={isAppInView(DRAWER_NATIVE_APPS.QUICK_SETTINGS, appInView)} />
64 const logo = <SidebarLogo to="/" app={APPS.PROTONDRIVE} />;
67 isHeaderExpanded={expanded}
68 toggleHeaderExpanded={toggleExpanded}
69 settingsButton={drawerSettingsButton}
73 const permissions = getDriveDrawerPermissions({ user });
74 const drawerSidebarButtons = [
75 permissions.contacts && (
76 <ContactDrawerAppButton aria-expanded={isAppInView(DRAWER_NATIVE_APPS.CONTACTS, appInView)} />
78 permissions.calendar && <CalendarDrawerAppButton aria-expanded={isAppInView(APPS.PROTONCALENDAR, appInView)} />,
81 const isNewUploadDisabled = location.pathname === '/devices' || isReadOnly;
86 primary={<ActionMenuButton className="hidden md:flex" disabled={isNewUploadDisabled} />}
87 isHeaderExpanded={expanded}
88 toggleHeaderExpanded={toggleExpanded}
92 const canShowDrawer = drawerSidebarButtons.length > 0;
99 drawerApp={<DrawerApp customAppSettings={<DriveQuickSettings />} />}
102 drawerSidebar={<DrawerSidebar buttons={drawerSidebarButtons} />}
103 drawerVisibilityButton={canShowDrawer ? <DrawerVisibilityButton /> : undefined}
104 mainBordered={canShowDrawer && !!showDrawerSidebar}
106 <div className="flex flex-column flex-nowrap w-full">
107 <AppErrorBoundary>{children}</AppErrorBoundary>
110 </PrivateAppContainer>
114 export default DriveWindow;