bigbuffet-rw/app/soapbox/features/ui/components/user_panel.js

105 lines
4.1 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';
import { Link } from 'react-router-dom';
import { injectIntl, FormattedMessage } from 'react-intl';
import { makeGetAccount } from '../../../selectors';
import ImmutablePropTypes from 'react-immutable-proptypes';
import ImmutablePureComponent from 'react-immutable-pure-component';
2020-05-28 15:52:07 -07:00
import Avatar from 'soapbox/components/avatar';
import { shortNumberFormat } from 'soapbox/utils/numbers';
import { acctFull } from 'soapbox/utils/accounts';
import StillImage from 'soapbox/components/still_image';
import VerificationBadge from 'soapbox/components/verification_badge';
2020-08-07 16:10:13 -07:00
import { List as ImmutableList } from 'immutable';
2020-03-27 13:59:38 -07:00
class UserPanel extends ImmutablePureComponent {
2020-04-14 11:44:40 -07:00
2020-03-27 13:59:38 -07:00
static propTypes = {
account: ImmutablePropTypes.map,
intl: PropTypes.object.isRequired,
domain: PropTypes.string,
}
render() {
2020-08-02 18:50:06 -07:00
const { account, intl, domain } = this.props;
if (!account) return null;
2020-03-27 13:59:38 -07:00
const displayNameHtml = { __html: account.get('display_name_html') };
const acct = account.get('acct').indexOf('@') === -1 && domain ? `${account.get('acct')}@${domain}` : account.get('acct');
2020-08-07 16:10:13 -07:00
const verified = account.getIn(['pleroma', 'tags'], ImmutableList()).includes('verified');
2020-03-27 13:59:38 -07:00
return (
2020-08-02 18:50:06 -07:00
<div className='user-panel'>
2020-03-27 13:59:38 -07:00
<div className='user-panel__container'>
<div className='user-panel__header'>
<StillImage src={account.get('header')} alt='' />
2020-03-27 13:59:38 -07:00
</div>
<div className='user-panel__profile'>
<Link to={`/@${account.get('acct')}`} title={acct}>
<Avatar account={account} />
</Link>
</div>
<div className='user-panel__meta'>
<div className='user-panel__account'>
<h1>
<Link to={`/@${account.get('acct')}`}>
<span className='user-panel__account__name' dangerouslySetInnerHTML={displayNameHtml} />
{verified && <VerificationBadge />}
2020-03-28 11:07:36 -07:00
<small className='user-panel__account__username'>@{acctFull(account)}</small>
2020-03-27 13:59:38 -07:00
</Link>
</h1>
</div>
<div className='user-panel__stats-block'>
<div className='user-panel-stats-item'>
<Link to={`/@${account.get('acct')}`} title={intl.formatNumber(account.get('statuses_count'))}>
<strong className='user-panel-stats-item__value'>{shortNumberFormat(account.get('statuses_count'))}</strong>
<span className='user-panel-stats-item__label'><FormattedMessage className='user-panel-stats-item__label' id='account.posts' defaultMessage='Posts' /></span>
</Link>
</div>
<div className='user-panel-stats-item'>
<Link to={`/@${account.get('acct')}/followers`} title={intl.formatNumber(account.get('followers_count'))}>
<strong className='user-panel-stats-item__value'>{shortNumberFormat(account.get('followers_count'))}</strong>
<span className='user-panel-stats-item__label'><FormattedMessage id='account.followers' defaultMessage='Followers' /></span>
</Link>
</div>
<div className='user-panel-stats-item'>
<Link to={`/@${account.get('acct')}/following`} title={intl.formatNumber(account.get('following_count'))}>
<strong className='user-panel-stats-item__value'>{shortNumberFormat(account.get('following_count'))}</strong>
<span className='user-panel-stats-item__label'><FormattedMessage className='user-panel-stats-item__label' id='account.follows' defaultMessage='Follows' /></span>
</Link>
</div>
</div>
</div>
</div>
</div>
2020-04-14 11:44:40 -07:00
);
2020-03-27 13:59:38 -07:00
}
2020-04-14 11:44:40 -07:00
2020-03-27 13:59:38 -07:00
};
2020-06-16 05:06:44 -07:00
const makeMapStateToProps = () => {
2020-03-27 13:59:38 -07:00
const getAccount = makeGetAccount();
2020-06-16 05:06:44 -07:00
const mapStateToProps = (state, { accountId }) => ({
account: getAccount(state, accountId),
});
return mapStateToProps;
2020-03-27 13:59:38 -07:00
};
export default injectIntl(
2020-06-16 05:06:44 -07:00
connect(makeMapStateToProps, null, null, {
2020-03-27 13:59:38 -07:00
forwardRef: true,
2020-04-17 15:00:25 -07:00
})(UserPanel));