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

78 lines
2.6 KiB
TypeScript
Raw Normal View History

2023-01-03 19:55:46 +00:00
// Copyright 2020 Signal Messenger, LLC
2020-10-30 20:34:04 +00:00
// SPDX-License-Identifier: AGPL-3.0-only
import React, { memo } from 'react';
import { useSelector } from 'react-redux';
2020-05-27 21:37:06 +00:00
import { ConversationHero } from '../../components/conversation/ConversationHero';
2021-11-02 23:01:13 +00:00
import { getPreferredBadgeSelector } from '../selectors/badges';
import { getIntl, getTheme } from '../selectors/user';
import { getHasStoriesSelector } from '../selectors/stories2';
2022-11-09 02:38:19 +00:00
import { isSignalConversation } from '../../util/isSignalConversation';
import { getConversationSelector } from '../selectors/conversations';
import { useConversationsActions } from '../ducks/conversations';
import { useGlobalModalActions } from '../ducks/globalModals';
import { useStoriesActions } from '../ducks/stories';
2020-05-27 21:37:06 +00:00
type SmartHeroRowProps = Readonly<{
2020-05-27 21:37:06 +00:00
id: string;
}>;
2020-05-27 21:37:06 +00:00
export const SmartHeroRow = memo(function SmartHeroRow({
id,
}: SmartHeroRowProps) {
const i18n = useSelector(getIntl);
const theme = useSelector(getTheme);
const getPreferredBadge = useSelector(getPreferredBadgeSelector);
const hasStoriesSelector = useSelector(getHasStoriesSelector);
const conversationSelector = useSelector(getConversationSelector);
const conversation = conversationSelector(id);
if (conversation == null) {
2020-05-27 21:37:06 +00:00
throw new Error(`Did not find conversation ${id} in state!`);
}
const badge = getPreferredBadge(conversation.badges);
const hasStories = hasStoriesSelector(id);
const isSignalConversationValue = isSignalConversation(conversation);
const { unblurAvatar, updateSharedGroups } = useConversationsActions();
const { toggleAboutContactModal } = useGlobalModalActions();
const { viewUserStories } = useStoriesActions();
const {
about,
acceptedMessageRequest,
avatarPath,
groupDescription,
isMe,
membersCount,
phoneNumber,
profileName,
sharedGroupNames,
title,
type,
unblurredAvatarPath,
} = conversation;
return (
<ConversationHero
about={about}
acceptedMessageRequest={acceptedMessageRequest}
avatarPath={avatarPath}
badge={badge}
conversationType={type}
groupDescription={groupDescription}
hasStories={hasStories}
i18n={i18n}
id={id}
isMe={isMe}
isSignalConversation={isSignalConversationValue}
membersCount={membersCount}
phoneNumber={phoneNumber}
profileName={profileName}
sharedGroupNames={sharedGroupNames}
theme={theme}
title={title}
toggleAboutContactModal={toggleAboutContactModal}
unblurAvatar={unblurAvatar}
unblurredAvatarPath={unblurredAvatarPath}
updateSharedGroups={updateSharedGroups}
viewUserStories={viewUserStories}
/>
);
});