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

229 lines
8 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, { memo, useCallback } from 'react';
2022-12-22 03:07:45 +00:00
import { useSelector } from 'react-redux';
2024-02-22 21:19:50 +00:00
import type { ButtonVariant } from '../../components/Button';
2022-12-22 03:07:45 +00:00
import { ErrorModal } from '../../components/ErrorModal';
import { GlobalModalContainer } from '../../components/GlobalModalContainer';
2024-02-16 22:16:13 +00:00
import { SmartAboutContactModal } from './AboutContactModal';
2022-12-22 03:07:45 +00:00
import { SmartAddUserToAnotherGroupModal } from './AddUserToAnotherGroupModal';
2021-09-21 22:37:10 +00:00
import { SmartContactModal } from './ContactModal';
2023-03-27 23:48:57 +00:00
import { SmartEditHistoryMessagesModal } from './EditHistoryMessagesModal';
2023-03-20 22:23:53 +00:00
import { SmartForwardMessagesModal } from './ForwardMessagesModal';
2022-07-01 00:52:03 +00:00
import { SmartProfileEditorModal } from './ProfileEditorModal';
import { SmartUsernameOnboardingModal } from './UsernameOnboardingModal';
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';
2024-02-16 22:16:13 +00:00
import { getConversationsStoppingSend } from '../selectors/conversations';
import { getIntl, getTheme } from '../selectors/user';
2022-12-22 03:07:45 +00:00
import { useGlobalModalActions } from '../ducks/globalModals';
import { SmartDeleteMessagesModal } from './DeleteMessagesModal';
2024-03-12 16:29:31 +00:00
import { SmartMessageRequestActionsConfirmation } from './MessageRequestActionsConfirmation';
import { getGlobalModalsState } from '../selectors/globalModals';
2024-03-26 19:48:33 +00:00
import { SmartEditNicknameAndNoteModal } from './EditNicknameAndNoteModal';
import { SmartNotePreviewModal } from './NotePreviewModal';
2024-06-10 15:23:43 +00:00
import { SmartCallLinkEditModal } from './CallLinkEditModal';
function renderCallLinkEditModal(): JSX.Element {
return <SmartCallLinkEditModal />;
}
2023-03-27 23:48:57 +00:00
function renderEditHistoryMessagesModal(): JSX.Element {
return <SmartEditHistoryMessagesModal />;
}
2024-03-26 19:48:33 +00:00
function renderEditNicknameAndNoteModal(): JSX.Element {
return <SmartEditNicknameAndNoteModal />;
}
2021-07-19 19:26:06 +00:00
function renderProfileEditor(): JSX.Element {
return <SmartProfileEditorModal />;
2021-07-19 19:26:06 +00:00
}
function renderUsernameOnboarding(): JSX.Element {
return <SmartUsernameOnboardingModal />;
}
2021-09-21 22:37:10 +00:00
function renderContactModal(): JSX.Element {
return <SmartContactModal />;
}
function renderDeleteMessagesModal(): JSX.Element {
return <SmartDeleteMessagesModal />;
}
2023-03-20 22:23:53 +00:00
function renderForwardMessagesModal(): JSX.Element {
return <SmartForwardMessagesModal />;
2022-07-01 00:52:03 +00:00
}
2024-03-12 16:29:31 +00:00
function renderMessageRequestActionsConfirmation(): JSX.Element {
return <SmartMessageRequestActionsConfirmation />;
}
2024-03-26 19:48:33 +00:00
function renderNotePreviewModal(): JSX.Element {
return <SmartNotePreviewModal />;
}
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 />;
}
2024-02-16 22:16:13 +00:00
function renderAboutContactModal(): JSX.Element {
return <SmartAboutContactModal />;
}
export const SmartGlobalModalContainer = memo(
function SmartGlobalModalContainer() {
const conversationsStoppingSend = useSelector(getConversationsStoppingSend);
const i18n = useSelector(getIntl);
const theme = useSelector(getTheme);
const hasSafetyNumberChangeModal = conversationsStoppingSend.length > 0;
const {
aboutContactModalContactId,
addUserToAnotherGroupModalContactId,
2024-06-10 15:23:43 +00:00
callLinkEditModalRoomId,
contactModalState,
deleteMessagesProps,
editHistoryMessages,
2024-03-26 19:48:33 +00:00
editNicknameAndNoteModalProps,
errorModalProps,
forwardMessagesProps,
messageRequestActionsConfirmationProps,
2024-03-26 19:48:33 +00:00
notePreviewModalProps,
isProfileEditorVisible,
isShortcutGuideModalVisible,
isSignalConnectionsVisible,
isStoriesSettingsVisible,
isWhatsNewVisible,
usernameOnboardingState,
safetyNumberChangedBlockingData,
safetyNumberModalContactId,
stickerPackPreviewId,
userNotFoundModalState,
} = useSelector(getGlobalModalsState);
const {
closeErrorModal,
hideUserNotFoundModal,
hideWhatsNewModal,
toggleSignalConnectionsModal,
} = useGlobalModalActions();
const renderAddUserToAnotherGroup = useCallback(() => {
return (
<SmartAddUserToAnotherGroupModal
contactID={String(addUserToAnotherGroupModalContactId)}
/>
);
}, [addUserToAnotherGroupModalContactId]);
const renderSafetyNumber = useCallback(
() => (
<SmartSafetyNumberModal
contactID={String(safetyNumberModalContactId)}
/>
),
[safetyNumberModalContactId]
2022-12-22 03:07:45 +00:00
);
const renderStickerPreviewModal = useCallback(
() =>
stickerPackPreviewId ? (
<SmartStickerPreviewModal packId={stickerPackPreviewId} />
) : null,
[stickerPackPreviewId]
);
const renderErrorModal = useCallback(
({
buttonVariant,
description,
title,
}: {
buttonVariant?: ButtonVariant;
description?: string;
title?: string;
}) => (
<ErrorModal
buttonVariant={buttonVariant}
description={description}
title={title}
i18n={i18n}
onClose={closeErrorModal}
/>
),
[closeErrorModal, i18n]
);
return (
<GlobalModalContainer
addUserToAnotherGroupModalContactId={
addUserToAnotherGroupModalContactId
}
2024-06-10 15:23:43 +00:00
callLinkEditModalRoomId={callLinkEditModalRoomId}
contactModalState={contactModalState}
editHistoryMessages={editHistoryMessages}
2024-03-26 19:48:33 +00:00
editNicknameAndNoteModalProps={editNicknameAndNoteModalProps}
errorModalProps={errorModalProps}
deleteMessagesProps={deleteMessagesProps}
forwardMessagesProps={forwardMessagesProps}
messageRequestActionsConfirmationProps={
messageRequestActionsConfirmationProps
}
2024-03-26 19:48:33 +00:00
notePreviewModalProps={notePreviewModalProps}
hasSafetyNumberChangeModal={hasSafetyNumberChangeModal}
hideUserNotFoundModal={hideUserNotFoundModal}
hideWhatsNewModal={hideWhatsNewModal}
2022-12-22 03:07:45 +00:00
i18n={i18n}
isAboutContactModalVisible={aboutContactModalContactId != null}
isProfileEditorVisible={isProfileEditorVisible}
isShortcutGuideModalVisible={isShortcutGuideModalVisible}
isSignalConnectionsVisible={isSignalConnectionsVisible}
isStoriesSettingsVisible={isStoriesSettingsVisible}
isWhatsNewVisible={isWhatsNewVisible}
renderAboutContactModal={renderAboutContactModal}
renderAddUserToAnotherGroup={renderAddUserToAnotherGroup}
2024-06-10 15:23:43 +00:00
renderCallLinkEditModal={renderCallLinkEditModal}
renderContactModal={renderContactModal}
renderEditHistoryMessagesModal={renderEditHistoryMessagesModal}
2024-03-26 19:48:33 +00:00
renderEditNicknameAndNoteModal={renderEditNicknameAndNoteModal}
renderErrorModal={renderErrorModal}
renderDeleteMessagesModal={renderDeleteMessagesModal}
renderForwardMessagesModal={renderForwardMessagesModal}
renderMessageRequestActionsConfirmation={
renderMessageRequestActionsConfirmation
}
2024-03-26 19:48:33 +00:00
renderNotePreviewModal={renderNotePreviewModal}
renderProfileEditor={renderProfileEditor}
renderUsernameOnboarding={renderUsernameOnboarding}
renderSafetyNumber={renderSafetyNumber}
renderSendAnywayDialog={renderSendAnywayDialog}
renderShortcutGuideModal={renderShortcutGuideModal}
renderStickerPreviewModal={renderStickerPreviewModal}
renderStoriesSettings={renderStoriesSettings}
safetyNumberChangedBlockingData={safetyNumberChangedBlockingData}
safetyNumberModalContactId={safetyNumberModalContactId}
stickerPackPreviewId={stickerPackPreviewId}
theme={theme}
toggleSignalConnectionsModal={toggleSignalConnectionsModal}
userNotFoundModalState={userNotFoundModalState}
usernameOnboardingState={usernameOnboardingState}
/>
);
}
);