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,37 +1,47 @@
// Copyright 2022 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import { connect } from 'react-redux';
import { mapDispatchToProps } from '../actions';
import { useSelector } from 'react-redux';
import React, { memo } from 'react';
import { AddUserToAnotherGroupModal } from '../../components/AddUserToAnotherGroupModal';
import type { StateType } from '../reducer';
import {
getAllGroupsWithInviteAccess,
getContactSelector,
} from '../selectors/conversations';
import { getIntl, getRegionCode, getTheme } from '../selectors/user';
import { getIntl, getRegionCode } from '../selectors/user';
import { useToastActions } from '../ducks/toast';
import { useGlobalModalActions } from '../ducks/globalModals';
import { useConversationsActions } from '../ducks/conversations';
export type Props = {
export type SmartAddUserToAnotherGroupModalProps = Readonly<{
contactID: string;
};
}>;
const mapStateToProps = (state: StateType, props: Props) => {
const candidateConversations = getAllGroupsWithInviteAccess(state);
const getContact = getContactSelector(state);
export const SmartAddUserToAnotherGroupModal = memo(
function SmartAddUserToAnotherGroupModal({
contactID,
}: SmartAddUserToAnotherGroupModalProps) {
const i18n = useSelector(getIntl);
const candidateConversations = useSelector(getAllGroupsWithInviteAccess);
const getContact = useSelector(getContactSelector);
const regionCode = useSelector(getRegionCode);
const regionCode = getRegionCode(state);
const { toggleAddUserToAnotherGroupModal } = useGlobalModalActions();
const { addMembersToGroup } = useConversationsActions();
const { showToast } = useToastActions();
return {
contact: getContact(props.contactID),
i18n: getIntl(state),
theme: getTheme(state),
candidateConversations,
regionCode,
};
};
const contact = getContact(contactID);
const smart = connect(mapStateToProps, mapDispatchToProps);
export const SmartAddUserToAnotherGroupModal = smart(
AddUserToAnotherGroupModal
return (
<AddUserToAnotherGroupModal
contact={contact}
i18n={i18n}
candidateConversations={candidateConversations}
regionCode={regionCode}
toggleAddUserToAnotherGroupModal={toggleAddUserToAnotherGroupModal}
addMembersToGroup={addMembersToGroup}
showToast={showToast}
/>
);
}
);