2021-03-09 19:16:56 +00:00
|
|
|
// Copyright 2021 Signal Messenger, LLC
|
2021-01-29 21:19:24 +00:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2021-06-02 00:24:28 +00:00
|
|
|
import React, { ReactNode } from 'react';
|
2021-01-29 21:19:24 +00:00
|
|
|
|
|
|
|
import { Avatar } from '../../Avatar';
|
2021-05-10 22:38:18 +00:00
|
|
|
import { Emojify } from '../Emojify';
|
2021-01-29 21:19:24 +00:00
|
|
|
import { LocalizerType } from '../../../types/Util';
|
|
|
|
import { ConversationType } from '../../../state/ducks/conversations';
|
2021-06-02 00:24:28 +00:00
|
|
|
import { GroupDescription } from '../GroupDescription';
|
2021-05-13 14:47:30 +00:00
|
|
|
import { GroupV2Membership } from './ConversationDetailsMembershipList';
|
2021-01-29 21:19:24 +00:00
|
|
|
import { bemGenerator } from './util';
|
|
|
|
|
|
|
|
export type Props = {
|
2021-03-09 19:16:56 +00:00
|
|
|
canEdit: boolean;
|
2021-01-29 21:19:24 +00:00
|
|
|
conversation: ConversationType;
|
2021-03-09 19:16:56 +00:00
|
|
|
i18n: LocalizerType;
|
2021-05-13 14:47:30 +00:00
|
|
|
memberships: Array<GroupV2Membership>;
|
2021-03-09 19:16:56 +00:00
|
|
|
startEditing: () => void;
|
2021-01-29 21:19:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const bem = bemGenerator('module-conversation-details-header');
|
|
|
|
|
|
|
|
export const ConversationDetailsHeader: React.ComponentType<Props> = ({
|
2021-03-09 19:16:56 +00:00
|
|
|
canEdit,
|
2021-01-29 21:19:24 +00:00
|
|
|
conversation,
|
2021-03-09 19:16:56 +00:00
|
|
|
i18n,
|
2021-05-13 14:47:30 +00:00
|
|
|
memberships,
|
2021-03-09 19:16:56 +00:00
|
|
|
startEditing,
|
2021-01-29 21:19:24 +00:00
|
|
|
}) => {
|
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(),
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2021-03-09 19:16:56 +00:00
|
|
|
const contents = (
|
|
|
|
<>
|
2021-01-29 21:19:24 +00:00
|
|
|
<Avatar
|
|
|
|
conversationType="group"
|
|
|
|
i18n={i18n}
|
|
|
|
size={80}
|
|
|
|
{...conversation}
|
2021-05-07 22:21:10 +00:00
|
|
|
sharedGroupNames={[]}
|
2021-01-29 21:19:24 +00:00
|
|
|
/>
|
|
|
|
<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>
|
2021-01-29 21:19:24 +00:00
|
|
|
</div>
|
2021-03-09 19:16:56 +00:00
|
|
|
</>
|
2021-01-29 21:19:24 +00:00
|
|
|
);
|
2021-03-09 19:16:56 +00:00
|
|
|
|
|
|
|
if (canEdit) {
|
|
|
|
return (
|
|
|
|
<button
|
|
|
|
type="button"
|
2021-06-02 00:24:28 +00:00
|
|
|
onClick={ev => {
|
|
|
|
ev.preventDefault();
|
|
|
|
ev.stopPropagation();
|
|
|
|
startEditing();
|
|
|
|
}}
|
2021-03-09 19:16:56 +00:00
|
|
|
className={bem('root', 'editable')}
|
|
|
|
>
|
|
|
|
{contents}
|
|
|
|
</button>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return <div className={bem('root')}>{contents}</div>;
|
2021-01-29 21:19:24 +00:00
|
|
|
};
|