bigbuffet-rw/app/soapbox/components/display_name.js

51 lines
1.4 KiB
JavaScript
Raw Normal View History

2020-03-27 13:59:38 -07:00
import React from 'react';
import PropTypes from 'prop-types';
2020-03-27 13:59:38 -07:00
import ImmutablePropTypes from 'react-immutable-proptypes';
import VerificationBadge from './verification_badge';
2020-03-28 11:07:36 -07:00
import { acctFull } from '../utils/accounts';
2020-03-27 13:59:38 -07:00
export default class DisplayName extends React.PureComponent {
static propTypes = {
account: ImmutablePropTypes.map.isRequired,
others: ImmutablePropTypes.list,
children: PropTypes.node,
2020-03-27 13:59:38 -07:00
};
render() {
const { account, others, children } = this.props;
2020-03-27 13:59:38 -07:00
let displayName, suffix;
2020-03-27 13:59:38 -07:00
if (others && others.size > 1) {
displayName = others.take(2).map(a => [
<bdi key={a.get('id')}>
<strong className='display-name__html' dangerouslySetInnerHTML={{ __html: a.get('display_name_html') }} />
</bdi>,
2020-04-14 11:44:40 -07:00
a.get('is_verified') && <VerificationBadge />,
2020-03-27 13:59:38 -07:00
]).reduce((prev, cur) => [prev, ', ', cur]);
if (others.size - 2 > 0) {
suffix = `+${others.size - 2}`;
}
} else {
displayName = (
<>
<bdi><strong className='display-name__html' dangerouslySetInnerHTML={{ __html: account.get('display_name_html') }} /></bdi>
{account.get('is_verified') && <VerificationBadge />}
</>
);
2020-03-28 11:07:36 -07:00
suffix = <span className='display-name__account'>@{acctFull(account)}</span>;
2020-03-27 13:59:38 -07:00
}
return (
<span className='display-name'>
{displayName}
{suffix}
{children}
2020-03-27 13:59:38 -07:00
</span>
);
}
}