signal-desktop/ts/components/conversation/conversation-details/ConversationDetailsHeader.tsx

84 lines
2 KiB
TypeScript
Raw Normal View History

// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
2021-06-02 00:24:28 +00:00
import React, { ReactNode } from 'react';
import { Avatar } from '../../Avatar';
2021-05-10 22:38:18 +00:00
import { Emojify } from '../Emojify';
import { LocalizerType } from '../../../types/Util';
import { ConversationType } from '../../../state/ducks/conversations';
2021-06-02 00:24:28 +00:00
import { GroupDescription } from '../GroupDescription';
import { GroupV2Membership } from './ConversationDetailsMembershipList';
import { bemGenerator } from './util';
export type Props = {
canEdit: boolean;
conversation: ConversationType;
i18n: LocalizerType;
memberships: Array<GroupV2Membership>;
startEditing: () => void;
};
const bem = bemGenerator('module-conversation-details-header');
export const ConversationDetailsHeader: React.ComponentType<Props> = ({
canEdit,
conversation,
i18n,
memberships,
startEditing,
}) => {
2021-06-02 00:24:28 +00:00
let subtitle: ReactNode;
if (conversation.groupDescription) {
subtitle = (
<GroupDescription
i18n={i18n}
text={conversation.groupDescription}
title={conversation.title}
/>
);
} else if (canEdit) {
subtitle = i18n('ConversationDetailsHeader--add-group-description');
} else {
subtitle = i18n('ConversationDetailsHeader--members', [
memberships.length.toString(),
]);
}
const contents = (
<>
<Avatar
conversationType="group"
i18n={i18n}
size={80}
{...conversation}
2021-05-07 22:21:10 +00:00
sharedGroupNames={[]}
/>
<div>
2021-05-10 22:38:18 +00:00
<div className={bem('title')}>
<Emojify text={conversation.title} />
</div>
2021-06-02 00:24:28 +00:00
<div className={bem('subtitle')}>{subtitle}</div>
</div>
</>
);
if (canEdit) {
return (
<button
type="button"
2021-06-02 00:24:28 +00:00
onClick={ev => {
ev.preventDefault();
ev.stopPropagation();
startEditing();
}}
className={bem('root', 'editable')}
>
{contents}
</button>
);
}
return <div className={bem('root')}>{contents}</div>;
};