signal-desktop/ts/components/ContactListItem.tsx

97 lines
2.4 KiB
TypeScript
Raw Normal View History

// Copyright 2018-2021 Signal Messenger, LLC
2020-10-30 20:34:04 +00:00
// SPDX-License-Identifier: AGPL-3.0-only
import React from 'react';
import classNames from 'classnames';
2021-01-26 01:01:19 +00:00
import { About } from './conversation/About';
import { Avatar } from './Avatar';
import { Emojify } from './conversation/Emojify';
2020-07-24 01:35:32 +00:00
import { InContactsIcon } from './InContactsIcon';
import { LocalizerType } from '../types/Util';
import { ColorType } from '../types/Colors';
type Props = {
2021-01-26 01:01:19 +00:00
about?: string;
avatarPath?: string;
2020-09-09 02:25:05 +00:00
color?: ColorType;
2019-01-14 21:49:58 +00:00
i18n: LocalizerType;
2020-09-09 02:25:05 +00:00
isAdmin?: boolean;
isMe?: boolean;
name?: string;
onClick?: () => void;
2020-09-09 02:25:05 +00:00
phoneNumber?: string;
profileName?: string;
title: string;
};
export class ContactListItem extends React.Component<Props> {
2020-09-12 00:46:52 +00:00
public renderAvatar(): JSX.Element {
const {
avatarPath,
i18n,
color,
name,
phoneNumber,
profileName,
2020-07-24 01:35:32 +00:00
title,
} = this.props;
return (
<Avatar
avatarPath={avatarPath}
color={color}
conversationType="direct"
i18n={i18n}
name={name}
phoneNumber={phoneNumber}
profileName={profileName}
2020-07-24 01:35:32 +00:00
title={title}
2019-10-04 18:06:17 +00:00
size={52}
/>
);
}
2020-09-12 00:46:52 +00:00
public render(): JSX.Element {
2021-01-26 01:01:19 +00:00
const { about, i18n, isAdmin, isMe, name, onClick, title } = this.props;
const displayName = isMe ? i18n('you') : title;
2020-07-24 01:35:32 +00:00
const shouldShowIcon = Boolean(name);
return (
2019-11-07 21:36:16 +00:00
<button
onClick={onClick}
className={classNames(
'module-contact-list-item',
onClick ? 'module-contact-list-item--with-click-handler' : null
)}
2020-09-12 00:46:52 +00:00
type="button"
>
{this.renderAvatar()}
<div className="module-contact-list-item__text">
2020-09-09 02:25:05 +00:00
<div className="module-contact-list-item__left">
<div className="module-contact-list-item__text__name">
<Emojify text={displayName} />
{shouldShowIcon ? (
<span>
{' '}
<InContactsIcon i18n={i18n} />
</span>
) : null}
</div>
<div className="module-contact-list-item__text__additional-data">
2021-01-26 01:01:19 +00:00
<About text={about} />
2020-09-09 02:25:05 +00:00
</div>
</div>
2020-09-09 02:25:05 +00:00
{isAdmin ? (
<div className="module-contact-list-item__admin">
{i18n('GroupV2--admin')}
</div>
) : null}
</div>
2019-11-07 21:36:16 +00:00
</button>
);
}
}