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

136 lines
4.4 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
2022-12-22 03:07:45 +00:00
import React, { useCallback } from 'react';
import { useSelector } from 'react-redux';
import type { GlobalModalsStateType } from '../ducks/globalModals';
import type { StateType } from '../reducer';
2022-12-22 03:07:45 +00:00
import { ErrorModal } from '../../components/ErrorModal';
import { GlobalModalContainer } from '../../components/GlobalModalContainer';
2022-12-22 03:07:45 +00:00
import { SmartAddUserToAnotherGroupModal } from './AddUserToAnotherGroupModal';
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';
2022-12-22 03:07:45 +00:00
import { SmartShortcutGuideModal } from './ShortcutGuideModal';
import { SmartStickerPreviewModal } from './StickerPreviewModal';
import { SmartStoriesSettingsModal } from './StoriesSettingsModal';
import { getConversationsStoppingSend } from '../selectors/conversations';
import { getIntl, getTheme } from '../selectors/user';
2022-12-22 03:07:45 +00:00
import { useGlobalModalActions } from '../ducks/globalModals';
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 />;
}
2022-12-22 03:07:45 +00:00
function renderShortcutGuideModal(): JSX.Element {
return <SmartShortcutGuideModal />;
}
export function SmartGlobalModalContainer(): JSX.Element {
const conversationsStoppingSend = useSelector(getConversationsStoppingSend);
const i18n = useSelector(getIntl);
const theme = useSelector(getTheme);
const hasSafetyNumberChangeModal = conversationsStoppingSend.length > 0;
const {
addUserToAnotherGroupModalContactId,
isProfileEditorVisible,
isSignalConnectionsVisible,
isShortcutGuideModalVisible,
isStoriesSettingsVisible,
isWhatsNewVisible,
safetyNumberModalContactId,
stickerPackPreviewId,
} = useSelector<StateType, GlobalModalsStateType>(
state => state.globalModals
);
const {
closeErrorModal,
hideWhatsNewModal,
hideUserNotFoundModal,
toggleSignalConnectionsModal,
} = useGlobalModalActions();
const renderAddUserToAnotherGroup = useCallback(() => {
return (
<SmartAddUserToAnotherGroupModal
contactID={String(addUserToAnotherGroupModalContactId)}
/>
);
}, [addUserToAnotherGroupModalContactId]);
const renderSafetyNumber = useCallback(
() => (
<SmartSafetyNumberModal contactID={String(safetyNumberModalContactId)} />
),
[safetyNumberModalContactId]
);
const renderStickerPreviewModal = useCallback(
() =>
stickerPackPreviewId ? (
<SmartStickerPreviewModal packId={stickerPackPreviewId} />
) : null,
2022-12-22 03:07:45 +00:00
[stickerPackPreviewId]
);
const renderErrorModal = useCallback(
({ description, title }: { description?: string; title?: string }) => (
<ErrorModal
title={title}
description={description}
i18n={i18n}
onClose={closeErrorModal}
/>
),
2022-12-22 03:07:45 +00:00
[closeErrorModal, i18n]
);
return (
<GlobalModalContainer
hasSafetyNumberChangeModal={hasSafetyNumberChangeModal}
hideUserNotFoundModal={hideUserNotFoundModal}
hideWhatsNewModal={hideWhatsNewModal}
i18n={i18n}
isProfileEditorVisible={isProfileEditorVisible}
isShortcutGuideModalVisible={isShortcutGuideModalVisible}
isSignalConnectionsVisible={isSignalConnectionsVisible}
isStoriesSettingsVisible={isStoriesSettingsVisible}
isWhatsNewVisible={isWhatsNewVisible}
renderAddUserToAnotherGroup={renderAddUserToAnotherGroup}
renderContactModal={renderContactModal}
renderErrorModal={renderErrorModal}
renderForwardMessageModal={renderForwardMessageModal}
renderProfileEditor={renderProfileEditor}
renderSafetyNumber={renderSafetyNumber}
renderSendAnywayDialog={renderSendAnywayDialog}
renderShortcutGuideModal={renderShortcutGuideModal}
renderStickerPreviewModal={renderStickerPreviewModal}
renderStoriesSettings={renderStoriesSettings}
theme={theme}
toggleSignalConnectionsModal={toggleSignalConnectionsModal}
/>
);
}