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,38 +1,43 @@
// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import { connect } from 'react-redux';
import { useSelector } from 'react-redux';
import React, { memo } from 'react';
import { ConversationNotificationsSettings } from '../../components/conversation/conversation-details/ConversationNotificationsSettings';
import type { StateType } from '../reducer';
import { getIntl } from '../selectors/user';
import { getConversationByIdSelector } from '../selectors/conversations';
import { strictAssert } from '../../util/assert';
import { mapDispatchToProps } from '../actions';
import { useConversationsActions } from '../ducks/conversations';
export type OwnProps = {
export type SmartConversationNotificationsSettingsProps = {
conversationId: string;
};
const mapStateToProps = (state: StateType, props: OwnProps) => {
const { conversationId } = props;
const conversationSelector = getConversationByIdSelector(state);
const conversation = conversationSelector(conversationId);
strictAssert(conversation, 'Expected a conversation to be found');
return {
id: conversationId,
conversationType: conversation.type,
dontNotifyForMentionsIfMuted: Boolean(
conversation.dontNotifyForMentionsIfMuted
),
i18n: getIntl(state),
muteExpiresAt: conversation.muteExpiresAt,
};
};
const smart = connect(mapStateToProps, mapDispatchToProps);
export const SmartConversationNotificationsSettings = smart(
ConversationNotificationsSettings
export const SmartConversationNotificationsSettings = memo(
function SmartConversationNotificationsSettings({
conversationId,
}: SmartConversationNotificationsSettingsProps) {
const i18n = useSelector(getIntl);
const conversationSelector = useSelector(getConversationByIdSelector);
const { setMuteExpiration, setDontNotifyForMentionsIfMuted } =
useConversationsActions();
const conversation = conversationSelector(conversationId);
strictAssert(conversation, 'Expected a conversation to be found');
const {
type: conversationType,
dontNotifyForMentionsIfMuted,
muteExpiresAt,
} = conversation;
return (
<ConversationNotificationsSettings
id={conversationId}
conversationType={conversationType}
dontNotifyForMentionsIfMuted={dontNotifyForMentionsIfMuted ?? false}
i18n={i18n}
muteExpiresAt={muteExpiresAt}
setMuteExpiration={setMuteExpiration}
setDontNotifyForMentionsIfMuted={setDontNotifyForMentionsIfMuted}
/>
);
}
);