2023-01-03 19:55:46 +00:00
|
|
|
// Copyright 2021 Signal Messenger, LLC
|
2021-07-30 18:35:43 +00:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2021-10-26 19:15:33 +00:00
|
|
|
import React, { useEffect } from 'react';
|
2021-09-29 20:59:37 +00:00
|
|
|
import { Globals } from '@react-spring/web';
|
2021-06-14 19:01:00 +00:00
|
|
|
import classNames from 'classnames';
|
|
|
|
|
2022-07-12 16:41:41 +00:00
|
|
|
import type { ExecuteMenuRoleType } from './TitleBarContainer';
|
|
|
|
import type { MenuOptionsType, MenuActionType } from '../types/menu';
|
2022-12-15 00:48:36 +00:00
|
|
|
import type { ToastType } from '../types/Toast';
|
2022-08-19 18:35:40 +00:00
|
|
|
import type { ViewStoryActionCreatorType } from '../state/ducks/stories';
|
2023-01-02 21:34:41 +00:00
|
|
|
import type { LocalizerType, ReplacementValuesType } from '../types/Util';
|
2022-09-26 16:24:52 +00:00
|
|
|
import { ThemeType } from '../types/Util';
|
2021-06-14 19:01:00 +00:00
|
|
|
import { AppViewType } from '../state/ducks/app';
|
2021-12-16 15:02:22 +00:00
|
|
|
import { SmartInstallScreen } from '../state/smart/InstallScreen';
|
2021-06-14 19:01:00 +00:00
|
|
|
import { StandaloneRegistration } from './StandaloneRegistration';
|
2022-07-12 16:41:41 +00:00
|
|
|
import { TitleBarContainer } from './TitleBarContainer';
|
|
|
|
import { ToastManager } from './ToastManager';
|
2021-09-17 22:24:21 +00:00
|
|
|
import { usePageVisibility } from '../hooks/usePageVisibility';
|
2021-09-29 20:59:37 +00:00
|
|
|
import { useReducedMotion } from '../hooks/useReducedMotion';
|
2021-06-14 19:01:00 +00:00
|
|
|
|
2021-08-31 20:58:39 +00:00
|
|
|
type PropsType = {
|
2021-06-14 19:01:00 +00:00
|
|
|
appView: AppViewType;
|
2022-03-04 21:14:52 +00:00
|
|
|
openInbox: () => void;
|
|
|
|
registerSingleDevice: (number: string, code: string) => Promise<void>;
|
2021-06-17 21:15:09 +00:00
|
|
|
renderCallManager: () => JSX.Element;
|
|
|
|
renderGlobalModalContainer: () => JSX.Element;
|
2022-03-04 21:14:52 +00:00
|
|
|
isShowingStoriesView: boolean;
|
2023-01-02 21:34:41 +00:00
|
|
|
i18n: LocalizerType;
|
2022-08-19 18:35:40 +00:00
|
|
|
renderStories: (closeView: () => unknown) => JSX.Element;
|
2022-07-29 20:22:55 +00:00
|
|
|
hasSelectedStoryData: boolean;
|
2022-08-19 18:35:40 +00:00
|
|
|
renderStoryViewer: (closeView: () => unknown) => JSX.Element;
|
2022-12-10 02:02:22 +00:00
|
|
|
renderLightbox: () => JSX.Element | null;
|
2021-11-30 17:51:53 +00:00
|
|
|
requestVerification: (
|
|
|
|
type: 'sms' | 'voice',
|
|
|
|
number: string,
|
|
|
|
token: string
|
|
|
|
) => Promise<void>;
|
2021-06-14 19:01:00 +00:00
|
|
|
theme: ThemeType;
|
2022-06-08 22:00:32 +00:00
|
|
|
isMaximized: boolean;
|
|
|
|
isFullScreen: boolean;
|
|
|
|
menuOptions: MenuOptionsType;
|
2022-12-21 03:25:10 +00:00
|
|
|
onUndoArchive: (conversationId: string) => unknown;
|
2022-12-14 18:12:04 +00:00
|
|
|
openFileInFolder: (target: string) => unknown;
|
2022-07-05 16:44:53 +00:00
|
|
|
hasCustomTitleBar: boolean;
|
2022-06-20 18:26:31 +00:00
|
|
|
hideMenuBar: boolean;
|
2022-06-08 22:00:32 +00:00
|
|
|
|
|
|
|
executeMenuRole: ExecuteMenuRoleType;
|
|
|
|
executeMenuAction: (action: MenuActionType) => void;
|
2022-12-09 19:11:14 +00:00
|
|
|
hideToast: () => unknown;
|
2022-06-08 22:00:32 +00:00
|
|
|
titleBarDoubleClick: () => void;
|
2022-09-26 16:24:52 +00:00
|
|
|
toast?: {
|
|
|
|
toastType: ToastType;
|
|
|
|
parameters?: ReplacementValuesType;
|
|
|
|
};
|
2022-12-09 19:11:14 +00:00
|
|
|
scrollToMessage: (conversationId: string, messageId: string) => unknown;
|
2022-08-19 18:35:40 +00:00
|
|
|
toggleStoriesView: () => unknown;
|
|
|
|
viewStory: ViewStoryActionCreatorType;
|
2023-01-02 21:34:41 +00:00
|
|
|
renderInbox: () => JSX.Element;
|
|
|
|
};
|
2021-06-14 19:01:00 +00:00
|
|
|
|
2022-11-18 00:45:19 +00:00
|
|
|
export function App({
|
2021-06-14 19:01:00 +00:00
|
|
|
appView,
|
2022-06-16 19:12:50 +00:00
|
|
|
executeMenuAction,
|
|
|
|
executeMenuRole,
|
2023-01-02 21:34:41 +00:00
|
|
|
hasCustomTitleBar,
|
2022-07-29 20:22:55 +00:00
|
|
|
hasSelectedStoryData,
|
2022-06-20 18:26:31 +00:00
|
|
|
hideMenuBar,
|
2022-07-12 16:41:41 +00:00
|
|
|
hideToast,
|
2021-08-31 20:58:39 +00:00
|
|
|
i18n,
|
2022-06-08 22:00:32 +00:00
|
|
|
isFullScreen,
|
2022-06-16 19:12:50 +00:00
|
|
|
isMaximized,
|
|
|
|
isShowingStoriesView,
|
2022-06-08 22:00:32 +00:00
|
|
|
menuOptions,
|
2022-12-21 03:25:10 +00:00
|
|
|
onUndoArchive,
|
2022-12-14 18:12:04 +00:00
|
|
|
openFileInFolder,
|
2023-01-02 21:34:41 +00:00
|
|
|
openInbox,
|
2022-06-16 19:12:50 +00:00
|
|
|
registerSingleDevice,
|
2021-06-17 21:15:09 +00:00
|
|
|
renderCallManager,
|
|
|
|
renderGlobalModalContainer,
|
2023-01-02 21:34:41 +00:00
|
|
|
renderInbox,
|
2022-12-10 02:02:22 +00:00
|
|
|
renderLightbox,
|
2022-03-04 21:14:52 +00:00
|
|
|
renderStories,
|
2022-07-06 19:06:20 +00:00
|
|
|
renderStoryViewer,
|
2021-11-30 17:51:53 +00:00
|
|
|
requestVerification,
|
2021-06-14 19:01:00 +00:00
|
|
|
theme,
|
2022-06-08 22:00:32 +00:00
|
|
|
titleBarDoubleClick,
|
2022-09-26 16:24:52 +00:00
|
|
|
toast,
|
2022-08-19 18:35:40 +00:00
|
|
|
toggleStoriesView,
|
|
|
|
viewStory,
|
2022-11-18 00:45:19 +00:00
|
|
|
}: PropsType): JSX.Element {
|
2021-06-14 19:01:00 +00:00
|
|
|
let contents;
|
|
|
|
|
|
|
|
if (appView === AppViewType.Installer) {
|
2021-12-16 15:02:22 +00:00
|
|
|
contents = <SmartInstallScreen />;
|
2021-06-14 19:01:00 +00:00
|
|
|
} else if (appView === AppViewType.Standalone) {
|
2021-11-30 17:51:53 +00:00
|
|
|
const onComplete = () => {
|
|
|
|
window.removeSetupMenuItems();
|
|
|
|
openInbox();
|
|
|
|
};
|
|
|
|
contents = (
|
|
|
|
<StandaloneRegistration
|
|
|
|
onComplete={onComplete}
|
|
|
|
requestVerification={requestVerification}
|
|
|
|
registerSingleDevice={registerSingleDevice}
|
|
|
|
/>
|
|
|
|
);
|
2021-06-14 19:01:00 +00:00
|
|
|
} else if (appView === AppViewType.Inbox) {
|
2023-01-02 21:34:41 +00:00
|
|
|
contents = renderInbox();
|
2021-06-14 19:01:00 +00:00
|
|
|
}
|
|
|
|
|
2021-07-30 18:35:43 +00:00
|
|
|
// This are here so that themes are properly applied to anything that is
|
2021-06-17 21:15:09 +00:00
|
|
|
// created in a portal and exists outside of the <App /> container.
|
|
|
|
useEffect(() => {
|
|
|
|
document.body.classList.remove('light-theme');
|
|
|
|
document.body.classList.remove('dark-theme');
|
|
|
|
|
|
|
|
if (theme === ThemeType.dark) {
|
|
|
|
document.body.classList.add('dark-theme');
|
|
|
|
}
|
|
|
|
if (theme === ThemeType.light) {
|
|
|
|
document.body.classList.add('light-theme');
|
|
|
|
}
|
|
|
|
}, [theme]);
|
|
|
|
|
2021-07-30 18:35:43 +00:00
|
|
|
const isPageVisible = usePageVisibility();
|
|
|
|
useEffect(() => {
|
|
|
|
document.body.classList.toggle('page-is-visible', isPageVisible);
|
|
|
|
}, [isPageVisible]);
|
|
|
|
|
2021-09-29 20:59:37 +00:00
|
|
|
// A11y settings for react-spring
|
|
|
|
const prefersReducedMotion = useReducedMotion();
|
|
|
|
useEffect(() => {
|
|
|
|
Globals.assign({
|
|
|
|
skipAnimation: prefersReducedMotion,
|
|
|
|
});
|
|
|
|
}, [prefersReducedMotion]);
|
|
|
|
|
2021-06-14 19:01:00 +00:00
|
|
|
return (
|
2022-06-08 22:00:32 +00:00
|
|
|
<TitleBarContainer
|
|
|
|
theme={theme}
|
|
|
|
isMaximized={isMaximized}
|
|
|
|
isFullScreen={isFullScreen}
|
2022-07-05 16:44:53 +00:00
|
|
|
hasCustomTitleBar={hasCustomTitleBar}
|
2022-06-20 18:26:31 +00:00
|
|
|
executeMenuRole={executeMenuRole}
|
|
|
|
titleBarDoubleClick={titleBarDoubleClick}
|
2022-06-08 22:00:32 +00:00
|
|
|
hasMenu
|
2022-06-20 18:26:31 +00:00
|
|
|
hideMenuBar={hideMenuBar}
|
2022-09-27 21:01:06 +00:00
|
|
|
i18n={i18n}
|
2022-06-08 22:00:32 +00:00
|
|
|
menuOptions={menuOptions}
|
|
|
|
executeMenuAction={executeMenuAction}
|
2021-06-14 19:01:00 +00:00
|
|
|
>
|
2022-06-08 22:00:32 +00:00
|
|
|
<div
|
|
|
|
className={classNames({
|
|
|
|
App: true,
|
|
|
|
'light-theme': theme === ThemeType.light,
|
|
|
|
'dark-theme': theme === ThemeType.dark,
|
|
|
|
})}
|
|
|
|
>
|
2022-12-14 18:12:04 +00:00
|
|
|
<ToastManager
|
|
|
|
hideToast={hideToast}
|
|
|
|
i18n={i18n}
|
2022-12-21 03:25:10 +00:00
|
|
|
onUndoArchive={onUndoArchive}
|
2022-12-14 18:12:04 +00:00
|
|
|
openFileInFolder={openFileInFolder}
|
|
|
|
toast={toast}
|
|
|
|
/>
|
2022-06-08 22:00:32 +00:00
|
|
|
{renderGlobalModalContainer()}
|
|
|
|
{renderCallManager()}
|
2022-12-10 02:02:22 +00:00
|
|
|
{renderLightbox()}
|
2022-08-19 18:35:40 +00:00
|
|
|
{isShowingStoriesView && renderStories(toggleStoriesView)}
|
|
|
|
{hasSelectedStoryData &&
|
|
|
|
renderStoryViewer(() => viewStory({ closeViewer: true }))}
|
2022-06-08 22:00:32 +00:00
|
|
|
{contents}
|
|
|
|
</div>
|
|
|
|
</TitleBarContainer>
|
2021-06-14 19:01:00 +00:00
|
|
|
);
|
2022-11-18 00:45:19 +00:00
|
|
|
}
|