// Copyright 2021 Signal Messenger, LLC // SPDX-License-Identifier: AGPL-3.0-only import React, { ComponentProps, useEffect } from 'react'; import { Globals } from '@react-spring/web'; 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 '../hooks/usePageVisibility'; import { useReducedMotion } from '../hooks/useReducedMotion'; type PropsType = { appView: AppViewType; renderCallManager: () => JSX.Element; renderGlobalModalContainer: () => JSX.Element; theme: ThemeType; } & ComponentProps; export const App = ({ appView, cancelMessagesPendingConversationVerification, conversationsStoppingMessageSendBecauseOfVerification, hasInitialLoadCompleted, i18n, isCustomizingPreferredReactions, numberOfMessagesPendingBecauseOfVerification, renderCallManager, renderCustomizingPreferredReactionsModal, renderGlobalModalContainer, renderSafetyNumber, theme, verifyConversationsStoppingMessageSend, }: PropsType): JSX.Element => { let contents; if (appView === AppViewType.Installer) { contents = ; } else if (appView === AppViewType.Standalone) { contents = ; } else if (appView === AppViewType.Inbox) { contents = ( ); } // This are here so that themes are properly applied to anything that is // created in a portal and exists outside of the 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]); return (
{renderGlobalModalContainer()} {renderCallManager()} {contents}
); };