signal-desktop/ts/state/smart/App.tsx

106 lines
3.7 KiB
TypeScript
Raw Normal View History

2022-03-04 21:14:52 +00:00
// Copyright 2021-2022 Signal Messenger, LLC
2021-06-17 21:15:09 +00:00
// SPDX-License-Identifier: AGPL-3.0-only
import React from 'react';
import { connect } from 'react-redux';
import type { MenuItemConstructorOptions } from 'electron';
2021-06-17 21:15:09 +00:00
import type { MenuActionType } from '../../types/menu';
import { App } from '../../components/App';
2021-06-17 21:15:09 +00:00
import { SmartCallManager } from './CallManager';
import { SmartCustomizingPreferredReactionsModal } from './CustomizingPreferredReactionsModal';
2021-06-17 21:15:09 +00:00
import { SmartGlobalModalContainer } from './GlobalModalContainer';
2022-06-16 19:12:50 +00:00
import { SmartLeftPane } from './LeftPane';
2022-03-04 21:14:52 +00:00
import { SmartStories } from './Stories';
2022-07-06 19:06:20 +00:00
import { SmartStoryViewer } from './StoryViewer';
import type { StateType } from '../reducer';
import {
getIntl,
getLocaleMessages,
getTheme,
getIsMainWindowMaximized,
getIsMainWindowFullScreen,
getMenuOptions,
} from '../selectors/user';
2022-07-06 19:06:20 +00:00
import {
hasSelectedStoryData,
2022-07-06 19:06:20 +00:00
shouldShowStoriesView,
} from '../selectors/stories';
import { getHideMenuBar } from '../selectors/items';
import { getIsCustomizingPreferredReactions } from '../selectors/preferredReactions';
2021-06-17 21:15:09 +00:00
import { mapDispatchToProps } from '../actions';
2022-07-29 00:10:07 +00:00
import { ErrorBoundary } from '../../components/ErrorBoundary';
import { ModalContainer } from '../../components/ModalContainer';
2021-06-17 21:15:09 +00:00
const mapStateToProps = (state: StateType) => {
2022-07-29 00:10:07 +00:00
const i18n = getIntl(state);
2021-06-17 21:15:09 +00:00
return {
...state.app,
2022-07-29 00:10:07 +00:00
i18n,
localeMessages: getLocaleMessages(state),
isCustomizingPreferredReactions: getIsCustomizingPreferredReactions(state),
isMaximized: getIsMainWindowMaximized(state),
isFullScreen: getIsMainWindowFullScreen(state),
menuOptions: getMenuOptions(state),
2022-07-05 16:44:53 +00:00
hasCustomTitleBar: window.SignalContext.OS.hasCustomTitleBar(),
hideMenuBar: getHideMenuBar(state),
renderCallManager: () => (
<ModalContainer className="module-calling__modal-container">
<SmartCallManager />
</ModalContainer>
),
renderCustomizingPreferredReactionsModal: () => (
<SmartCustomizingPreferredReactionsModal />
),
2021-06-17 21:15:09 +00:00
renderGlobalModalContainer: () => <SmartGlobalModalContainer />,
2022-06-16 19:12:50 +00:00
renderLeftPane: () => <SmartLeftPane />,
2022-03-04 21:14:52 +00:00
isShowingStoriesView: shouldShowStoriesView(state),
renderStories: (closeView: () => unknown) => (
<ErrorBoundary name="App/renderStories" closeView={closeView}>
2022-07-29 00:10:07 +00:00
<SmartStories />
</ErrorBoundary>
),
hasSelectedStoryData: hasSelectedStoryData(state),
renderStoryViewer: (closeView: () => unknown) => (
<ErrorBoundary name="App/renderStoryViewer" closeView={closeView}>
2022-07-29 00:10:07 +00:00
<SmartStoryViewer />
</ErrorBoundary>
),
2021-11-30 17:51:53 +00:00
requestVerification: (
type: 'sms' | 'voice',
number: string,
token: string
): Promise<void> => {
const accountManager = window.getAccountManager();
if (type === 'sms') {
return accountManager.requestSMSVerification(number, token);
}
return accountManager.requestVoiceVerification(number, token);
},
registerSingleDevice: (number: string, code: string): Promise<void> => {
return window.getAccountManager().registerSingleDevice(number, code);
},
2022-06-16 19:12:50 +00:00
selectedConversationId: state.conversations.selectedConversationId,
selectedMessage: state.conversations.selectedMessage,
2021-06-17 21:15:09 +00:00
theme: getTheme(state),
executeMenuRole: (role: MenuItemConstructorOptions['role']): void => {
window.SignalContext.executeMenuRole(role);
},
executeMenuAction: (action: MenuActionType): void => {
window.SignalContext.executeMenuAction(action);
},
titleBarDoubleClick: (): void => {
window.titleBarDoubleClick();
},
toast: state.toast.toast,
2021-06-17 21:15:09 +00:00
};
};
const smart = connect(mapStateToProps, mapDispatchToProps);
export const SmartApp = smart(App);