2021-07-30 18:35:43 +00:00
|
|
|
// Copyright 2021 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { ComponentProps } from 'react';
|
|
|
|
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';
|
|
|
|
|
|
|
|
import { AppViewType } from '../state/ducks/app';
|
|
|
|
import { Inbox } from './Inbox';
|
|
|
|
import { Install } from './Install';
|
|
|
|
import { StandaloneRegistration } from './StandaloneRegistration';
|
|
|
|
import { ThemeType } from '../types/Util';
|
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;
|
2021-06-17 21:15:09 +00:00
|
|
|
renderCallManager: () => JSX.Element;
|
|
|
|
renderGlobalModalContainer: () => JSX.Element;
|
2021-06-14 19:01:00 +00:00
|
|
|
theme: ThemeType;
|
2021-08-31 20:58:39 +00:00
|
|
|
} & ComponentProps<typeof Inbox>;
|
2021-06-14 19:01:00 +00:00
|
|
|
|
|
|
|
export const App = ({
|
|
|
|
appView,
|
2021-08-31 20:58:39 +00:00
|
|
|
cancelMessagesPendingConversationVerification,
|
|
|
|
conversationsStoppingMessageSendBecauseOfVerification,
|
2021-06-14 19:01:00 +00:00
|
|
|
hasInitialLoadCompleted,
|
2021-11-17 21:58:34 +00:00
|
|
|
getPreferredBadge,
|
2021-08-31 20:58:39 +00:00
|
|
|
i18n,
|
2021-09-09 16:29:01 +00:00
|
|
|
isCustomizingPreferredReactions,
|
2021-08-31 20:58:39 +00:00
|
|
|
numberOfMessagesPendingBecauseOfVerification,
|
2021-06-17 21:15:09 +00:00
|
|
|
renderCallManager,
|
2021-09-09 16:29:01 +00:00
|
|
|
renderCustomizingPreferredReactionsModal,
|
2021-06-17 21:15:09 +00:00
|
|
|
renderGlobalModalContainer,
|
2021-08-31 20:58:39 +00:00
|
|
|
renderSafetyNumber,
|
2021-06-14 19:01:00 +00:00
|
|
|
theme,
|
2021-08-31 20:58:39 +00:00
|
|
|
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) {
|
2021-08-31 20:58:39 +00:00
|
|
|
contents = (
|
|
|
|
<Inbox
|
|
|
|
cancelMessagesPendingConversationVerification={
|
|
|
|
cancelMessagesPendingConversationVerification
|
|
|
|
}
|
|
|
|
conversationsStoppingMessageSendBecauseOfVerification={
|
|
|
|
conversationsStoppingMessageSendBecauseOfVerification
|
|
|
|
}
|
|
|
|
hasInitialLoadCompleted={hasInitialLoadCompleted}
|
2021-11-17 21:58:34 +00:00
|
|
|
getPreferredBadge={getPreferredBadge}
|
2021-08-31 20:58:39 +00:00
|
|
|
i18n={i18n}
|
2021-09-09 16:29:01 +00:00
|
|
|
isCustomizingPreferredReactions={isCustomizingPreferredReactions}
|
2021-08-31 20:58:39 +00:00
|
|
|
numberOfMessagesPendingBecauseOfVerification={
|
|
|
|
numberOfMessagesPendingBecauseOfVerification
|
|
|
|
}
|
2021-09-09 16:29:01 +00:00
|
|
|
renderCustomizingPreferredReactionsModal={
|
|
|
|
renderCustomizingPreferredReactionsModal
|
|
|
|
}
|
2021-08-31 20:58:39 +00:00
|
|
|
renderSafetyNumber={renderSafetyNumber}
|
2021-11-17 21:58:34 +00:00
|
|
|
theme={theme}
|
2021-08-31 20:58:39 +00:00
|
|
|
verifyConversationsStoppingMessageSend={
|
|
|
|
verifyConversationsStoppingMessageSend
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
);
|
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 (
|
|
|
|
<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>
|
|
|
|
);
|
|
|
|
};
|