signal-desktop/ts/components/ContactListItem.tsx

111 lines
2.7 KiB
TypeScript
Raw Normal View History

import React from 'react';
import classNames from 'classnames';
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';
interface Props {
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;
isVerified?: 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 {
const {
i18n,
2020-09-09 02:25:05 +00:00
isAdmin,
isMe,
isVerified,
name,
onClick,
phoneNumber,
profileName,
2020-07-24 01:35:32 +00:00
title,
} = this.props;
const displayName = isMe ? i18n('you') : title;
2020-07-24 01:35:32 +00:00
const shouldShowIcon = Boolean(name);
2020-07-24 01:35:32 +00:00
const showNumber = Boolean(isMe || name || profileName);
const showVerified = !isMe && isVerified;
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">
{showVerified ? (
<div className="module-contact-list-item__text__verified-icon" />
) : null}
{showVerified ? ` ${i18n('verified')}` : null}
{showVerified && showNumber ? ' ∙ ' : null}
{showNumber ? phoneNumber : null}
</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>
);
}
}