1 import type { SyntheticEvent } from 'react';
3 import { c } from 'ttag';
5 import { Button, CircleLoader } from '@proton/atoms';
6 import Icon from '@proton/components/components/icon/Icon';
7 import TextLoader from '@proton/components/components/loader/TextLoader';
8 import Tooltip from '@proton/components/components/tooltip/Tooltip';
9 import useConfig from '@proton/components/hooks/useConfig';
10 import useDocumentTitle from '@proton/components/hooks/useDocumentTitle';
11 import { getAppName } from '@proton/shared/lib/apps/helper';
12 import { getAppFromPathnameSafe } from '@proton/shared/lib/apps/slugHelper';
13 import { closeDrawerFromChildApp, getIsAuthorizedApp } from '@proton/shared/lib/drawer/helpers';
14 import { getIsIframe } from '@proton/shared/lib/helpers/browser';
15 import protonSpinner from '@proton/styles/assets/img/loading-spinners/proton-spinner.svg';
16 import clsx from '@proton/utils/clsx';
19 documentTitle?: string;
21 loaderClassName?: string;
24 const LoaderPage = ({ documentTitle = '', text, loaderClassName = '' }: Props) => {
25 const { APP_NAME } = useConfig();
27 const isIframe = getIsIframe();
28 const parentApp = getAppFromPathnameSafe(window.location.pathname);
29 const isDrawerApp = isIframe && !!parentApp && getIsAuthorizedApp(parentApp);
31 const appName = getAppName(APP_NAME);
32 const textToDisplay = text || c('Info').t`Loading ${appName}`;
34 useDocumentTitle(documentTitle || appName);
36 const handleCloseIFrame = () => {
40 closeDrawerFromChildApp(parentApp, APP_NAME);
43 const preventDefaultEvent = (e: SyntheticEvent) => e.preventDefault();
47 className="loader-page h-full"
48 // Ignore drag & drop during loading to avoid issue when user drops
49 // file too soon before the app is ready causing stop of the app
50 // load and showing the file instead.
51 onDragOver={preventDefaultEvent}
52 onDragEnter={preventDefaultEvent}
53 onDragEnd={preventDefaultEvent}
54 onDrop={preventDefaultEvent}
56 <div className={clsx(['absolute inset-center text-center', isDrawerApp && 'w-9/10'])}>
57 {isDrawerApp && <CircleLoader className="m-auto color-primary" size="medium" />}
61 className={clsx(['w-custom', loaderClassName])}
62 style={{ '--w-custom': '10em' }}
69 <TextLoader className="color-weak">{textToDisplay}</TextLoader>
72 <div className="header pl-4 flex justify-end items-center">
73 <Tooltip title={c('Action').t`Close`}>
74 <Button icon color="weak" shape="ghost" onClick={handleCloseIFrame}>
75 <Icon name="cross-big" size={4} />
84 export default LoaderPage;