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

80 lines
2.5 KiB
TypeScript
Raw Normal View History

2021-05-28 16:15:17 +00:00
// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import React from 'react';
import { connect } from 'react-redux';
import type { StateType } from '../reducer';
import { GlobalModalContainer } from '../../components/GlobalModalContainer';
2021-09-21 22:37:10 +00:00
import { SmartContactModal } from './ContactModal';
2022-07-01 00:52:03 +00:00
import { SmartForwardMessageModal } from './ForwardMessageModal';
import { SmartProfileEditorModal } from './ProfileEditorModal';
import { SmartSafetyNumberModal } from './SafetyNumberModal';
import { SmartSendAnywayDialog } from './SendAnywayDialog';
import { SmartStoriesSettingsModal } from './StoriesSettingsModal';
import { getConversationsStoppingSend } from '../selectors/conversations';
import { mapDispatchToProps } from '../actions';
2021-07-19 19:26:06 +00:00
import { getIntl, getTheme } from '../selectors/user';
import { SmartAddUserToAnotherGroupModal } from './AddUserToAnotherGroupModal';
import { SmartStickerPreviewModal } from './StickerPreviewModal';
2021-07-19 19:26:06 +00:00
function renderProfileEditor(): JSX.Element {
return <SmartProfileEditorModal />;
2021-07-19 19:26:06 +00:00
}
2021-09-21 22:37:10 +00:00
function renderContactModal(): JSX.Element {
return <SmartContactModal />;
}
2022-07-01 00:52:03 +00:00
function renderForwardMessageModal(): JSX.Element {
return <SmartForwardMessageModal />;
}
function renderStoriesSettings(): JSX.Element {
return <SmartStoriesSettingsModal />;
}
function renderSendAnywayDialog(): JSX.Element {
return <SmartSendAnywayDialog />;
}
2021-05-28 16:15:17 +00:00
const mapStateToProps = (state: StateType) => {
const i18n = getIntl(state);
const { stickerPackPreviewId } = state.globalModals;
2021-05-28 16:15:17 +00:00
return {
...state.globalModals,
hasSafetyNumberChangeModal: getConversationsStoppingSend(state).length > 0,
i18n,
theme: getTheme(state),
2021-09-21 22:37:10 +00:00
renderContactModal,
2022-07-01 00:52:03 +00:00
renderForwardMessageModal,
2021-07-19 19:26:06 +00:00
renderProfileEditor,
renderStoriesSettings,
renderStickerPreviewModal: () =>
stickerPackPreviewId ? (
<SmartStickerPreviewModal packId={stickerPackPreviewId} />
) : null,
renderSafetyNumber: () => (
<SmartSafetyNumberModal
contactID={String(state.globalModals.safetyNumberModalContactId)}
/>
),
renderAddUserToAnotherGroup: () => {
return (
<SmartAddUserToAnotherGroupModal
contactID={String(
state.globalModals.addUserToAnotherGroupModalContactId
)}
/>
);
},
renderSendAnywayDialog,
2021-05-28 16:15:17 +00:00
};
};
const smart = connect(mapStateToProps, mapDispatchToProps);
export const SmartGlobalModalContainer = smart(GlobalModalContainer);