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,34 +1,38 @@
// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import { connect } from 'react-redux';
import { mapDispatchToProps } from '../actions';
import React, { memo } from 'react';
import { useSelector } from 'react-redux';
import type { PropsType as GroupV2JoinDialogPropsType } from '../../components/GroupV2JoinDialog';
import { GroupV2JoinDialog } from '../../components/GroupV2JoinDialog';
import type { StateType } from '../reducer';
import { getIntl } from '../selectors/user';
import { getPreJoinConversation } from '../selectors/conversations';
export type PropsType = Pick<GroupV2JoinDialogPropsType, 'join' | 'onClose'>;
export type SmartGroupV2JoinDialogProps = Pick<
GroupV2JoinDialogPropsType,
'join' | 'onClose'
>;
const mapStateToProps = (
state: StateType,
props: PropsType
): GroupV2JoinDialogPropsType => {
const preJoinConversation = getPreJoinConversation(state);
if (!preJoinConversation) {
export const SmartGroupV2JoinDialog = memo(function SmartGroupV2JoinDialog({
join,
onClose,
}: SmartGroupV2JoinDialogProps) {
const i18n = useSelector(getIntl);
const preJoinConversation = useSelector(getPreJoinConversation);
if (preJoinConversation == null) {
throw new Error('smart/GroupV2JoinDialog: No pre-join conversation!');
}
return {
...props,
...preJoinConversation,
i18n: getIntl(state),
};
};
const smart = connect(mapStateToProps, mapDispatchToProps);
export const SmartGroupV2JoinDialog = smart(GroupV2JoinDialog);
const { memberCount, title, groupDescription, approvalRequired, avatar } =
preJoinConversation;
return (
<GroupV2JoinDialog
approvalRequired={approvalRequired}
avatar={avatar}
groupDescription={groupDescription}
i18n={i18n}
join={join}
memberCount={memberCount}
onClose={onClose}
title={title}
/>
);
});