signal-desktop/ts/components/App.tsx

180 lines
5.3 KiB
TypeScript
Raw Normal View History

// Copyright 2021-2022 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import type { ComponentProps } from 'react';
import React, { useEffect } from 'react';
import { Globals } from '@react-spring/web';
2021-06-14 19:01:00 +00:00
import classNames from 'classnames';
import { AppViewType } from '../state/ducks/app';
import { Inbox } from './Inbox';
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';
import { ThemeType } from '../types/Util';
import type { LocaleMessagesType } from '../types/I18N';
2021-09-17 22:24:21 +00:00
import { usePageVisibility } from '../hooks/usePageVisibility';
import { useReducedMotion } from '../hooks/useReducedMotion';
import type { MenuOptionsType, MenuActionType } from '../types/menu';
import { TitleBarContainer } from './TitleBarContainer';
import type { ExecuteMenuRoleType } from './TitleBarContainer';
2021-06-14 19:01:00 +00:00
type PropsType = {
2021-06-14 19:01:00 +00:00
appView: AppViewType;
localeMessages: LocaleMessagesType;
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;
renderStories: () => JSX.Element;
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;
isMaximized: boolean;
isFullScreen: boolean;
menuOptions: MenuOptionsType;
platform: string;
isWindows11: boolean;
hideMenuBar: boolean;
executeMenuRole: ExecuteMenuRoleType;
executeMenuAction: (action: MenuActionType) => void;
titleBarDoubleClick: () => void;
} & ComponentProps<typeof Inbox>;
2021-06-14 19:01:00 +00:00
export const App = ({
appView,
2022-02-16 18:36:21 +00:00
cancelConversationVerification,
conversationsStoppingSend,
2022-06-16 19:12:50 +00:00
executeMenuAction,
executeMenuRole,
getPreferredBadge,
2022-06-16 19:12:50 +00:00
hasInitialLoadCompleted,
hideMenuBar,
i18n,
isCustomizingPreferredReactions,
isFullScreen,
2022-06-16 19:12:50 +00:00
isMaximized,
isShowingStoriesView,
isWindows11,
2022-06-16 19:12:50 +00:00
localeMessages,
menuOptions,
2022-06-16 19:12:50 +00:00
openInbox,
platform,
2022-06-16 19:12:50 +00:00
registerSingleDevice,
2021-06-17 21:15:09 +00:00
renderCallManager,
renderCustomizingPreferredReactionsModal,
2021-06-17 21:15:09 +00:00
renderGlobalModalContainer,
2022-06-16 19:12:50 +00:00
renderLeftPane,
renderSafetyNumber,
2022-03-04 21:14:52 +00:00
renderStories,
2021-11-30 17:51:53 +00:00
requestVerification,
2022-06-16 19:12:50 +00:00
selectedConversationId,
selectedMessage,
showConversation,
showWhatsNewModal,
2021-06-14 19:01:00 +00:00
theme,
titleBarDoubleClick,
2022-06-16 19:12:50 +00:00
verifyConversationsStoppingSend,
2021-06-14 19:01:00 +00:00
}: PropsType): JSX.Element => {
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) {
contents = (
<Inbox
2022-02-16 18:36:21 +00:00
cancelConversationVerification={cancelConversationVerification}
conversationsStoppingSend={conversationsStoppingSend}
hasInitialLoadCompleted={hasInitialLoadCompleted}
getPreferredBadge={getPreferredBadge}
i18n={i18n}
isCustomizingPreferredReactions={isCustomizingPreferredReactions}
renderCustomizingPreferredReactionsModal={
renderCustomizingPreferredReactionsModal
}
2022-06-16 19:12:50 +00:00
renderLeftPane={renderLeftPane}
renderSafetyNumber={renderSafetyNumber}
2022-06-16 19:12:50 +00:00
selectedConversationId={selectedConversationId}
selectedMessage={selectedMessage}
showConversation={showConversation}
showWhatsNewModal={showWhatsNewModal}
theme={theme}
2022-02-16 18:36:21 +00:00
verifyConversationsStoppingSend={verifyConversationsStoppingSend}
/>
);
2021-06-14 19:01:00 +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]);
const isPageVisible = usePageVisibility();
useEffect(() => {
document.body.classList.toggle('page-is-visible', isPageVisible);
}, [isPageVisible]);
// A11y settings for react-spring
const prefersReducedMotion = useReducedMotion();
useEffect(() => {
Globals.assign({
skipAnimation: prefersReducedMotion,
});
}, [prefersReducedMotion]);
2021-06-14 19:01:00 +00:00
return (
<TitleBarContainer
theme={theme}
isMaximized={isMaximized}
isFullScreen={isFullScreen}
platform={platform}
isWindows11={isWindows11}
executeMenuRole={executeMenuRole}
titleBarDoubleClick={titleBarDoubleClick}
hasMenu
hideMenuBar={hideMenuBar}
localeMessages={localeMessages}
menuOptions={menuOptions}
executeMenuAction={executeMenuAction}
2021-06-14 19:01:00 +00:00
>
<div
className={classNames({
App: true,
'light-theme': theme === ThemeType.light,
'dark-theme': theme === ThemeType.dark,
})}
>
{renderGlobalModalContainer()}
{renderCallManager()}
{isShowingStoriesView && renderStories()}
{contents}
</div>
</TitleBarContainer>
2021-06-14 19:01:00 +00:00
);
};