/* * Wire * Copyright (C) 2022 Wire Swiss GmbH * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see http://www.gnu.org/licenses/. * */ import {FC, ReactNode, useContext, useEffect, useState} from 'react'; import cx from 'classnames'; import {CSSTransition, SwitchTransition} from 'react-transition-group'; import {container} from 'tsyringe'; import {ConnectRequests} from 'Components/ConnectRequests'; import {Conversation} from 'Components/Conversation'; import {HistoryExport} from 'Components/HistoryExport'; import {HistoryImport} from 'Components/HistoryImport'; import * as Icon from 'Components/Icon'; import {useLegalHoldModalState} from 'Components/Modals/LegalHoldModal/LegalHoldModal.state'; import {User} from 'src/script/entity/User'; import {useKoSubscribableChildren} from 'Util/ComponentUtil'; import {t} from 'Util/LocalizerUtil'; import {incomingCssClass, removeAnimationsClass} from 'Util/util'; import {Collection} from './panels/Collection'; import {AboutPreferences} from './panels/preferences/AboutPreferences'; import {AccountPreferences} from './panels/preferences/AccountPreferences'; import {AVPreferences} from './panels/preferences/AVPreferences'; import {DevicesPreferences} from './panels/preferences/DevicesPreferences'; import {OptionPreferences} from './panels/preferences/OptionPreferences'; import {ClientState} from '../../client/ClientState'; import {ConversationState} from '../../conversation/ConversationState'; import {TeamState} from '../../team/TeamState'; import {UserState} from '../../user/UserState'; import {RightSidebarParams} from '../AppMain'; import {PanelState} from '../RightSidebar'; import {RootContext} from '../RootProvider'; import {ContentState, useAppState} from '../useAppState'; export const ANIMATED_PAGE_TRANSITION_DURATION = 500; const Animated: FC<{children: ReactNode}> = ({children, ...rest}) => ( {children} ); interface MainContentProps { openRightSidebar: (panelState: PanelState, params: RightSidebarParams, compareEntityId?: boolean) => void; isRightSidebarOpen?: boolean; selfUser: User; conversationState?: ConversationState; reloadApp: () => void; } const MainContent: FC = ({ openRightSidebar, isRightSidebarOpen = false, selfUser, conversationState = container.resolve(ConversationState), reloadApp, }) => { const [uploadedFile, setUploadedFile] = useState(null); const mainViewModel = useContext(RootContext); const userState = container.resolve(UserState); const teamState = container.resolve(TeamState); const {showRequestModal} = useLegalHoldModalState(); const {isActivatedAccount} = useKoSubscribableChildren(selfUser, ['isActivatedAccount']); const contentState = useAppState(state => state.contentState); const isShowingConversation = useAppState(state => state.isShowingConversation); useEffect(() => { if (!isShowingConversation() && conversationState.activeConversation()) { // Reset active conversation for all states that do not require a loaded conversation conversationState.activeConversation(undefined); } }, [contentState, conversationState]); useEffect(() => { // Show legal hold on mount when legal hold is enabled for team if (teamState.supportsLegalHold()) { showRequestModal(true); } }, [teamState, showRequestModal]); if (!mainViewModel) { return null; } const {content: contentViewModel} = mainViewModel; const {isFederated, repositories, switchContent} = contentViewModel; // eslint-disable-next-line react-hooks/rules-of-hooks const {activeConversation} = useKoSubscribableChildren(conversationState, ['activeConversation']); const statesTitle: Partial> = { [ContentState.CONNECTION_REQUESTS]: t('accessibility.headings.connectionRequests'), [ContentState.CONVERSATION]: t('accessibility.headings.conversation'), [ContentState.HISTORY_EXPORT]: t('accessibility.headings.historyExport'), [ContentState.HISTORY_IMPORT]: t('accessibility.headings.historyImport'), [ContentState.COLLECTION]: t('accessibility.headings.collection'), [ContentState.PREFERENCES_ABOUT]: t('accessibility.headings.preferencesAbout'), [ContentState.PREFERENCES_ACCOUNT]: t('accessibility.headings.preferencesAccount'), [ContentState.PREFERENCES_AV]: t('accessibility.headings.preferencesAV'), [ContentState.PREFERENCES_DEVICES]: t('accessibility.headings.preferencesDevices'), [ContentState.PREFERENCES_OPTIONS]: t('accessibility.headings.preferencesOptions'), [ContentState.WATERMARK]: t('accessibility.headings.noConversation'), }; const title = statesTitle[contentState]; const onFileUpload = (file: File) => { switchContent(ContentState.HISTORY_IMPORT); setUploadedFile(file); }; return (

{title}

<> {contentState === ContentState.COLLECTION && activeConversation && ( )} {contentState === ContentState.PREFERENCES_ABOUT && (
)} {contentState === ContentState.PREFERENCES_ACCOUNT && (
)} {contentState === ContentState.PREFERENCES_AV && (
)} {contentState === ContentState.PREFERENCES_DEVICES && (
repositories.message.resetSession(userId, device.id, conversation) } selfUser={selfUser} verifyDevice={(userId, device, verified) => repositories.client.verifyClient(userId, device, verified) } />
)} {contentState === ContentState.PREFERENCES_OPTIONS && (
)} {contentState === ContentState.WATERMARK && (
)} {contentState === ContentState.CONNECTION_REQUESTS && ( )} {contentState === ContentState.CONVERSATION && ( )} {contentState === ContentState.HISTORY_EXPORT && ( )} {contentState === ContentState.HISTORY_IMPORT && uploadedFile && ( )}
); }; export {MainContent};