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

66 lines
1.9 KiB
JavaScript
Raw Normal View History

2020-03-27 13:59:38 -07:00
import React from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
2020-03-27 13:59:38 -07:00
import ImmutablePropTypes from 'react-immutable-proptypes';
import VerificationBadge from './verification_badge';
import { getAcct } from '../utils/accounts';
2020-08-05 11:04:32 -07:00
import { List as ImmutableList } from 'immutable';
import HoverRefWrapper from 'soapbox/components/hover_ref_wrapper';
import { displayFqn } from 'soapbox/utils/state';
2020-03-27 13:59:38 -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,
displayFqn: PropTypes.bool,
2020-03-27 13:59:38 -07:00
others: ImmutablePropTypes.list,
children: PropTypes.node,
2020-03-27 13:59:38 -07:00
};
render() {
const { account, displayFqn, others, children } = this.props;
2020-03-27 13:59:38 -07:00
let displayName, suffix;
2020-08-05 11:04:32 -07:00
const verified = account.getIn(['pleroma', 'tags'], ImmutableList()).includes('verified');
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>,
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>
{verified && <VerificationBadge />}
2020-03-27 13:59:38 -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'>
<HoverRefWrapper accountId={account.get('id')} inline>
{displayName}
</HoverRefWrapper>
2020-03-27 13:59:38 -07:00
{suffix}
{children}
2020-03-27 13:59:38 -07:00
</span>
);
}
}