2020-07-28 18:01:16 -07:00
|
|
|
import PropTypes from 'prop-types';
|
2022-01-10 14:17:52 -08:00
|
|
|
import React from 'react';
|
2020-03-27 13:59:38 -07:00
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
2022-01-10 14:17:52 -08:00
|
|
|
import { connect } from 'react-redux';
|
2022-01-10 14:25:06 -08:00
|
|
|
|
2020-09-11 10:17:32 -07:00
|
|
|
import HoverRefWrapper from 'soapbox/components/hover_ref_wrapper';
|
2022-01-10 14:17:52 -08:00
|
|
|
import { displayFqn } from 'soapbox/utils/state';
|
2022-01-10 14:25:06 -08:00
|
|
|
|
2022-01-10 14:01:24 -08:00
|
|
|
import { getAcct } from '../utils/accounts';
|
2022-01-10 14:25:06 -08:00
|
|
|
|
2022-01-10 14:01:24 -08:00
|
|
|
import Icon from './icon';
|
|
|
|
import RelativeTimestamp from './relative_timestamp';
|
2022-01-10 14:17:52 -08:00
|
|
|
import VerificationBadge from './verification_badge';
|
2020-03-27 13:59:38 -07:00
|
|
|
|
2021-04-10 12:13:07 -07:00
|
|
|
const mapStateToProps = state => {
|
|
|
|
return {
|
|
|
|
displayFqn: displayFqn(state),
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
export default @connect(mapStateToProps)
|
|
|
|
class DisplayName extends React.PureComponent {
|
2020-03-27 13:59:38 -07:00
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
account: ImmutablePropTypes.map.isRequired,
|
2021-04-10 12:13:07 -07:00
|
|
|
displayFqn: PropTypes.bool,
|
2020-03-27 13:59:38 -07:00
|
|
|
others: ImmutablePropTypes.list,
|
2020-07-28 18:01:16 -07:00
|
|
|
children: PropTypes.node,
|
2021-07-14 14:13:53 -07:00
|
|
|
withDate: PropTypes.bool,
|
2020-03-27 13:59:38 -07:00
|
|
|
};
|
|
|
|
|
2021-07-14 14:13:53 -07:00
|
|
|
static defaultProps = {
|
|
|
|
withDate: false,
|
|
|
|
}
|
|
|
|
|
2020-04-14 14:47:35 -07:00
|
|
|
render() {
|
2021-07-14 14:13:53 -07:00
|
|
|
const { account, displayFqn, others, children, withDate } = this.props;
|
2020-03-27 13:59:38 -07:00
|
|
|
|
2020-06-12 20:04:20 -07:00
|
|
|
let displayName, suffix;
|
2022-02-27 20:25:23 -08:00
|
|
|
const verified = account.get('verified');
|
2020-03-27 13:59:38 -07:00
|
|
|
|
2021-07-14 14:13:53 -07:00
|
|
|
const createdAt = account.get('created_at');
|
|
|
|
|
|
|
|
const joinedAt = createdAt ? (
|
|
|
|
<div className='account__joined-at'>
|
2021-09-27 21:47:43 -07:00
|
|
|
<Icon src={require('@tabler/icons/icons/clock.svg')} />
|
2021-07-14 14:13:53 -07:00
|
|
|
<RelativeTimestamp timestamp={createdAt} />
|
|
|
|
</div>
|
|
|
|
) : null;
|
|
|
|
|
2022-02-18 18:04:03 -08:00
|
|
|
if (others?.size > 1) {
|
2021-07-14 14:13:53 -07:00
|
|
|
displayName = others.take(2).map(a => (
|
2021-10-14 09:50:45 -07:00
|
|
|
<span className='display-name__name' key={a.get('id')}>
|
|
|
|
<bdi><strong className='display-name__html' dangerouslySetInnerHTML={{ __html: a.get('display_name_html') }} /></bdi>
|
2021-07-14 14:13:53 -07:00
|
|
|
{verified && <VerificationBadge />}
|
|
|
|
{withDate && joinedAt}
|
|
|
|
</span>
|
|
|
|
)).reduce((prev, cur) => [prev, ', ', cur]);
|
2020-03-27 13:59:38 -07:00
|
|
|
|
|
|
|
if (others.size - 2 > 0) {
|
|
|
|
suffix = `+${others.size - 2}`;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
displayName = (
|
2021-07-14 14:13:53 -07:00
|
|
|
<span className='display-name__name'>
|
2020-03-27 13:59:38 -07:00
|
|
|
<bdi><strong className='display-name__html' dangerouslySetInnerHTML={{ __html: account.get('display_name_html') }} /></bdi>
|
2020-08-05 10:08:52 -07:00
|
|
|
{verified && <VerificationBadge />}
|
2021-07-14 14:13:53 -07:00
|
|
|
{withDate && joinedAt}
|
|
|
|
</span>
|
2020-03-27 13:59:38 -07:00
|
|
|
);
|
2021-04-10 12:13:07 -07:00
|
|
|
suffix = <span className='display-name__account'>@{getAcct(account, displayFqn)}</span>;
|
2020-03-27 13:59:38 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<span className='display-name'>
|
2020-09-11 10:17:32 -07:00
|
|
|
<HoverRefWrapper accountId={account.get('id')} inline>
|
|
|
|
{displayName}
|
|
|
|
</HoverRefWrapper>
|
2020-03-27 13:59:38 -07:00
|
|
|
{suffix}
|
2020-07-28 18:01:16 -07:00
|
|
|
{children}
|
2020-03-27 13:59:38 -07:00
|
|
|
</span>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|