1 import type { FunctionComponent } from 'react';
2 import { useState } from 'react';
3 import { Router } from 'react-router-dom';
7 AuthenticationProvider,
15 StandardLoadErrorPage,
17 } from '@proton/components';
18 import useEffectOnce from '@proton/hooks/useEffectOnce';
19 import { ProtonStoreProvider } from '@proton/redux-shared-store';
20 import { getNonEmptyErrorMessage } from '@proton/shared/lib/helpers/error';
21 import type { UserModel } from '@proton/shared/lib/interfaces';
22 import { DRAWER_VISIBILITY } from '@proton/shared/lib/interfaces';
23 import type { UserSettingsResponse } from '@proton/shared/lib/interfaces/drive/userSettings';
24 import { FlagProvider } from '@proton/unleash';
25 import noop from '@proton/utils/noop';
27 import { bootstrapApp } from './bootstrap';
28 import * as config from './config';
29 import type { DriveStore } from './redux-store/store';
30 import { extraThunkArguments } from './redux-store/thunk';
31 import { UserSettingsProvider } from './store';
32 import { logPerformanceMarker } from './utils/performance';
35 initialUser?: UserModel;
36 initialDriveUserSettings?: UserSettingsResponse;
37 error?: { message: string } | undefined;
38 showDrawerSidebar?: boolean;
39 MainContainer?: FunctionComponent;
42 initialUser: undefined,
43 initialDriveUserSettings: undefined,
45 showDrawerSidebar: false,
49 const [state, setState] = useState(defaultState);
54 const { store, scopes, MainContainer, user, userSettings, driveUserSettings } = await bootstrapApp({
58 MainContainer: scopes.delinquent ? DelinquentContainer : MainContainer,
59 showDrawerSidebar: userSettings.HideSidePanel === DRAWER_VISIBILITY.SHOW,
60 initialDriveUserSettings: driveUserSettings,
64 logPerformanceMarker('drive_performance_clicktobootstrapped_histogram');
65 } catch (error: any) {
68 message: getNonEmptyErrorMessage(error),
76 <ProtonApp config={config}>
79 return <StandardLoadErrorPage errorMessage={state.error.message} />;
81 const loader = <LoaderPage />;
82 if (!state.MainContainer || !state.store || !state.initialUser || !state.initialDriveUserSettings) {
86 <ProtonStoreProvider store={state.store}>
87 <AuthenticationProvider store={extraThunkArguments.authentication}>
88 <FlagProvider unleashClient={extraThunkArguments.unleashClient} startClient={false}>
89 <Router history={extraThunkArguments.history}>
90 <EventManagerProvider eventManager={extraThunkArguments.eventManager}>
91 <ApiProvider api={extraThunkArguments.api}>
92 <DrawerProvider defaultShowDrawerSidear={state.showDrawerSidebar}>
93 <ErrorBoundary big component={<StandardErrorPage big />}>
95 hasReadableMemberKeyActivation
97 hasPrivateMemberKeyGeneration
100 <UserSettingsProvider
101 initialUser={state.initialUser}
102 initialDriveUserSettings={state.initialDriveUserSettings}
104 <state.MainContainer />
105 </UserSettingsProvider>
106 </StandardPrivateApp>
110 </EventManagerProvider>
113 </AuthenticationProvider>
114 </ProtonStoreProvider>