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

219 lines
7.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
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';
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';
2023-03-27 23:48:57 +00:00
function renderEditHistoryMessagesModal(): JSX.Element {
return <SmartEditHistoryMessagesModal />;
}
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 />;
}
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 />;
}
2022-12-22 03:07:45 +00:00
export function SmartGlobalModalContainer(): JSX.Element {
const conversationsStoppingSend = useSelector(getConversationsStoppingSend);
const i18n = useSelector(getIntl);
const theme = useSelector(getTheme);
const hasSafetyNumberChangeModal = conversationsStoppingSend.length > 0;
const {
2024-02-16 22:16:13 +00:00
aboutContactModalContactId,
2022-12-22 03:07:45 +00:00
addUserToAnotherGroupModalContactId,
authArtCreatorData,
2022-12-22 22:28:47 +00:00
contactModalState,
deleteMessagesProps,
2023-03-27 23:48:57 +00:00
editHistoryMessages,
2022-12-22 22:28:47 +00:00
errorModalProps,
formattingWarningData,
2023-03-20 22:23:53 +00:00
forwardMessagesProps,
2024-03-12 16:29:31 +00:00
messageRequestActionsConfirmationProps,
isAuthorizingArtCreator,
2022-12-22 03:07:45 +00:00
isProfileEditorVisible,
isShortcutGuideModalVisible,
2022-12-22 22:28:47 +00:00
isSignalConnectionsVisible,
2022-12-22 03:07:45 +00:00
isStoriesSettingsVisible,
isWhatsNewVisible,
usernameOnboardingState,
2022-12-22 22:28:47 +00:00
safetyNumberChangedBlockingData,
2022-12-22 03:07:45 +00:00
safetyNumberModalContactId,
sendEditWarningData,
2022-12-22 03:07:45 +00:00
stickerPackPreviewId,
2022-12-22 22:28:47 +00:00
userNotFoundModalState,
2022-12-22 03:07:45 +00:00
} = useSelector<StateType, GlobalModalsStateType>(
state => state.globalModals
);
const {
cancelAuthorizeArtCreator,
2022-12-22 03:07:45 +00:00
closeErrorModal,
confirmAuthorizeArtCreator,
2022-12-22 03:07:45 +00:00
hideUserNotFoundModal,
hideWhatsNewModal,
showFormattingWarningModal,
showSendEditWarningModal,
2022-12-22 03:07:45 +00:00
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(
2024-02-22 21:19:50 +00:00
({
buttonVariant,
description,
title,
}: {
buttonVariant?: ButtonVariant;
description?: string;
title?: string;
}) => (
2022-12-22 03:07:45 +00:00
<ErrorModal
2024-02-22 21:19:50 +00:00
buttonVariant={buttonVariant}
2022-12-22 03:07:45 +00:00
description={description}
2024-02-22 21:19:50 +00:00
title={title}
2022-12-22 03:07:45 +00:00
i18n={i18n}
onClose={closeErrorModal}
/>
),
2022-12-22 03:07:45 +00:00
[closeErrorModal, i18n]
);
return (
<GlobalModalContainer
2022-12-22 22:28:47 +00:00
addUserToAnotherGroupModalContactId={addUserToAnotherGroupModalContactId}
contactModalState={contactModalState}
2023-03-27 23:48:57 +00:00
editHistoryMessages={editHistoryMessages}
2022-12-22 22:28:47 +00:00
errorModalProps={errorModalProps}
deleteMessagesProps={deleteMessagesProps}
formattingWarningData={formattingWarningData}
2023-03-20 22:23:53 +00:00
forwardMessagesProps={forwardMessagesProps}
2024-03-12 16:29:31 +00:00
messageRequestActionsConfirmationProps={
messageRequestActionsConfirmationProps
}
2022-12-22 03:07:45 +00:00
hasSafetyNumberChangeModal={hasSafetyNumberChangeModal}
hideUserNotFoundModal={hideUserNotFoundModal}
hideWhatsNewModal={hideWhatsNewModal}
i18n={i18n}
2024-02-16 22:16:13 +00:00
isAboutContactModalVisible={aboutContactModalContactId != null}
2022-12-22 03:07:45 +00:00
isProfileEditorVisible={isProfileEditorVisible}
isShortcutGuideModalVisible={isShortcutGuideModalVisible}
isSignalConnectionsVisible={isSignalConnectionsVisible}
isStoriesSettingsVisible={isStoriesSettingsVisible}
isWhatsNewVisible={isWhatsNewVisible}
2024-02-16 22:16:13 +00:00
renderAboutContactModal={renderAboutContactModal}
2022-12-22 03:07:45 +00:00
renderAddUserToAnotherGroup={renderAddUserToAnotherGroup}
renderContactModal={renderContactModal}
2023-03-27 23:48:57 +00:00
renderEditHistoryMessagesModal={renderEditHistoryMessagesModal}
2022-12-22 03:07:45 +00:00
renderErrorModal={renderErrorModal}
renderDeleteMessagesModal={renderDeleteMessagesModal}
2023-03-20 22:23:53 +00:00
renderForwardMessagesModal={renderForwardMessagesModal}
2024-03-12 16:29:31 +00:00
renderMessageRequestActionsConfirmation={
renderMessageRequestActionsConfirmation
}
2022-12-22 03:07:45 +00:00
renderProfileEditor={renderProfileEditor}
renderUsernameOnboarding={renderUsernameOnboarding}
2022-12-22 03:07:45 +00:00
renderSafetyNumber={renderSafetyNumber}
renderSendAnywayDialog={renderSendAnywayDialog}
renderShortcutGuideModal={renderShortcutGuideModal}
renderStickerPreviewModal={renderStickerPreviewModal}
renderStoriesSettings={renderStoriesSettings}
2022-12-22 22:28:47 +00:00
safetyNumberChangedBlockingData={safetyNumberChangedBlockingData}
safetyNumberModalContactId={safetyNumberModalContactId}
sendEditWarningData={sendEditWarningData}
showFormattingWarningModal={showFormattingWarningModal}
showSendEditWarningModal={showSendEditWarningModal}
2022-12-22 22:28:47 +00:00
stickerPackPreviewId={stickerPackPreviewId}
2022-12-22 03:07:45 +00:00
theme={theme}
toggleSignalConnectionsModal={toggleSignalConnectionsModal}
2022-12-22 22:28:47 +00:00
userNotFoundModalState={userNotFoundModalState}
usernameOnboardingState={usernameOnboardingState}
2023-02-27 22:34:43 +00:00
isAuthorizingArtCreator={isAuthorizingArtCreator}
authArtCreatorData={authArtCreatorData}
cancelAuthorizeArtCreator={cancelAuthorizeArtCreator}
confirmAuthorizeArtCreator={confirmAuthorizeArtCreator}
2022-12-22 03:07:45 +00:00
/>
);
}