Refactor smart components

Co-authored-by: Fedor Indutny <79877362+indutny-signal@users.noreply.github.com>
This commit is contained in:
Jamie Kyle 2024-03-13 13:44:13 -07:00 committed by GitHub
parent 05c09ef769
commit 27b55e472d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
109 changed files with 3583 additions and 2629 deletions

View file

@ -1,11 +1,9 @@
// Copyright 2023 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import React, { useMemo } from 'react';
import React, { memo, useMemo } from 'react';
import { useSelector } from 'react-redux';
import type { GlobalModalsStateType } from '../ducks/globalModals';
import type { MessageAttributesType } from '../../model-types.d';
import type { StateType } from '../reducer';
import { EditHistoryMessagesModal } from '../../components/EditHistoryMessagesModal';
import { getIntl, getPlatform } from '../selectors/user';
import { getMessagePropsSelector } from '../selectors/message';
@ -14,49 +12,46 @@ import { useConversationsActions } from '../ducks/conversations';
import { useGlobalModalActions } from '../ducks/globalModals';
import { useLightboxActions } from '../ducks/lightbox';
import { strictAssert } from '../../util/assert';
import { getEditHistoryMessages } from '../selectors/globalModals';
export function SmartEditHistoryMessagesModal(): JSX.Element {
const i18n = useSelector(getIntl);
const platform = useSelector(getPlatform);
export const SmartEditHistoryMessagesModal = memo(
function SmartEditHistoryMessagesModal(): JSX.Element {
const i18n = useSelector(getIntl);
const platform = useSelector(getPlatform);
const { closeEditHistoryModal } = useGlobalModalActions();
const { closeEditHistoryModal } = useGlobalModalActions();
const { kickOffAttachmentDownload } = useConversationsActions();
const { showLightbox } = useLightboxActions();
const { kickOffAttachmentDownload } = useConversationsActions();
const { showLightbox } = useLightboxActions();
const getPreferredBadge = useSelector(getPreferredBadgeSelector);
const messagesAttributes = useSelector(getEditHistoryMessages);
const messagePropsSelector = useSelector(getMessagePropsSelector);
const getPreferredBadge = useSelector(getPreferredBadgeSelector);
strictAssert(messagesAttributes, 'messages not provided');
const { editHistoryMessages: messagesAttributes } = useSelector<
StateType,
GlobalModalsStateType
>(state => state.globalModals);
const editHistoryMessages = useMemo(() => {
return messagesAttributes.map(messageAttributes => ({
...messagePropsSelector(messageAttributes as MessageAttributesType),
// Make sure the messages don't get an "edited" badge
isEditedMessage: false,
// Do not show the same reactions in the message history UI
reactions: undefined,
// Make sure that the timestamp is the correct timestamp from attributes
// not the one that the selector derives.
timestamp: messageAttributes.timestamp,
}));
}, [messagesAttributes, messagePropsSelector]);
const messagePropsSelector = useSelector(getMessagePropsSelector);
strictAssert(messagesAttributes, 'messages not provided');
const editHistoryMessages = useMemo(() => {
return messagesAttributes.map(messageAttributes => ({
...messagePropsSelector(messageAttributes as MessageAttributesType),
// Make sure the messages don't get an "edited" badge
isEditedMessage: false,
// Do not show the same reactions in the message history UI
reactions: undefined,
// Make sure that the timestamp is the correct timestamp from attributes
// not the one that the selector derives.
timestamp: messageAttributes.timestamp,
}));
}, [messagesAttributes, messagePropsSelector]);
return (
<EditHistoryMessagesModal
closeEditHistoryModal={closeEditHistoryModal}
editHistoryMessages={editHistoryMessages}
getPreferredBadge={getPreferredBadge}
i18n={i18n}
platform={platform}
kickOffAttachmentDownload={kickOffAttachmentDownload}
showLightbox={showLightbox}
/>
);
}
return (
<EditHistoryMessagesModal
closeEditHistoryModal={closeEditHistoryModal}
editHistoryMessages={editHistoryMessages}
getPreferredBadge={getPreferredBadge}
i18n={i18n}
platform={platform}
kickOffAttachmentDownload={kickOffAttachmentDownload}
showLightbox={showLightbox}
/>
);
}
);