Signal-Desktop/ts/components/App.tsx

101 lines
3.0 KiB
TypeScript
Raw Normal View History

// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import React, { ComponentProps, useEffect } from 'react';
2021-06-14 19:01:00 +00:00
import classNames from 'classnames';
import { AppViewType } from '../state/ducks/app';
import { Inbox } from './Inbox';
import { Install } from './Install';
import { StandaloneRegistration } from './StandaloneRegistration';
import { ThemeType } from '../types/Util';
import { usePageVisibility } from '../util/hooks';
2021-06-14 19:01:00 +00:00
type PropsType = {
2021-06-14 19:01:00 +00:00
appView: AppViewType;
2021-06-17 21:15:09 +00:00
renderCallManager: () => JSX.Element;
renderGlobalModalContainer: () => JSX.Element;
2021-06-14 19:01:00 +00:00
theme: ThemeType;
} & ComponentProps<typeof Inbox>;
2021-06-14 19:01:00 +00:00
export const App = ({
appView,
cancelMessagesPendingConversationVerification,
conversationsStoppingMessageSendBecauseOfVerification,
2021-06-14 19:01:00 +00:00
hasInitialLoadCompleted,
i18n,
isCustomizingPreferredReactions,
numberOfMessagesPendingBecauseOfVerification,
2021-06-17 21:15:09 +00:00
renderCallManager,
renderCustomizingPreferredReactionsModal,
2021-06-17 21:15:09 +00:00
renderGlobalModalContainer,
renderSafetyNumber,
2021-06-14 19:01:00 +00:00
theme,
verifyConversationsStoppingMessageSend,
2021-06-14 19:01:00 +00:00
}: PropsType): JSX.Element => {
let contents;
if (appView === AppViewType.Installer) {
contents = <Install />;
} else if (appView === AppViewType.Standalone) {
contents = <StandaloneRegistration />;
} else if (appView === AppViewType.Inbox) {
contents = (
<Inbox
cancelMessagesPendingConversationVerification={
cancelMessagesPendingConversationVerification
}
conversationsStoppingMessageSendBecauseOfVerification={
conversationsStoppingMessageSendBecauseOfVerification
}
hasInitialLoadCompleted={hasInitialLoadCompleted}
i18n={i18n}
isCustomizingPreferredReactions={isCustomizingPreferredReactions}
numberOfMessagesPendingBecauseOfVerification={
numberOfMessagesPendingBecauseOfVerification
}
renderCustomizingPreferredReactionsModal={
renderCustomizingPreferredReactionsModal
}
renderSafetyNumber={renderSafetyNumber}
verifyConversationsStoppingMessageSend={
verifyConversationsStoppingMessageSend
}
/>
);
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]);
2021-06-14 19:01:00 +00:00
return (
<div
className={classNames({
App: true,
'light-theme': theme === ThemeType.light,
'dark-theme': theme === ThemeType.dark,
})}
>
2021-06-17 21:15:09 +00:00
{renderGlobalModalContainer()}
{renderCallManager()}
2021-06-14 19:01:00 +00:00
{contents}
</div>
);
};