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

150 lines
5.2 KiB
JavaScript
Raw Normal View History

2020-03-27 13:59:38 -07:00
import PropTypes from 'prop-types';
import React from 'react';
2020-03-27 13:59:38 -07:00
import ImmutablePropTypes from 'react-immutable-proptypes';
import ImmutablePureComponent from 'react-immutable-pure-component';
import { injectIntl, FormattedMessage } from 'react-intl';
import { connect } from 'react-redux';
import { Link } from 'react-router-dom';
2020-05-28 15:52:07 -07:00
import Avatar from 'soapbox/components/avatar';
import StillImage from 'soapbox/components/still_image';
import VerificationBadge from 'soapbox/components/verification_badge';
2022-02-27 20:25:23 -08:00
import { getAcct } from 'soapbox/utils/accounts';
import { shortNumberFormat } from 'soapbox/utils/numbers';
import { displayFqn } from 'soapbox/utils/state';
2022-03-21 11:09:01 -07:00
import { HStack, Stack, Text } from '../../../components/ui';
2022-01-10 14:01:24 -08:00
import { makeGetAccount } from '../../../selectors';
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,
displayFqn: PropTypes.bool,
2020-03-27 13:59:38 -07:00
intl: PropTypes.object.isRequired,
domain: PropTypes.string,
}
render() {
2022-03-21 11:09:01 -07:00
const { account, action, badges, displayFqn, 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');
const header = account.get('header');
2022-03-21 11:09:01 -07:00
const verified = account.get('verified');
2020-03-27 13:59:38 -07:00
return (
2022-03-21 11:09:01 -07:00
<div className='relative'>
<Stack space={2}>
<Stack>
<div className='-mt-4 -mx-4 h-24 bg-gray-200 relative'>
{header && (
<StillImage
src={account.get('header')}
className='absolute inset-0 object-cover'
alt=''
/>
)}
2020-03-27 13:59:38 -07:00
</div>
2022-03-21 11:09:01 -07:00
<HStack justifyContent='between'>
<Link
to={`/@${account.get('acct')}`}
title={acct}
className='-mt-12 block'
>
<Avatar
account={account}
className='h-20 w-20 bg-gray-50 ring-2 ring-white'
/>
</Link>
{action && (
<div className='mt-2'>{action}</div>
)}
</HStack>
</Stack>
<Stack>
<Link to={`/@${account.get('acct')}`}>
<HStack space={1} alignItems='center'>
<Text size='lg' weight='bold' dangerouslySetInnerHTML={displayNameHtml} />
{verified && <VerificationBadge />}
{badges.length > 0 && (
<HStack space={1} alignItems='center'>
{badges}
</HStack>
)}
</HStack>
</Link>
2020-03-27 13:59:38 -07:00
2022-03-21 11:09:01 -07:00
<Text size='sm' theme='muted'>
@{getAcct(account, displayFqn)}
</Text>
</Stack>
<HStack alignItems='center' space={3}>
{account.get('statuses_count') >= 0 && (
<Link to={`/@${account.get('acct')}`} title={intl.formatNumber(account.get('statuses_count'))}>
<HStack alignItems='center' space={1}>
<Text theme='primary' weight='bold' size='sm'>
{shortNumberFormat(account.get('statuses_count'))}
</Text>
<Text weight='bold' size='sm'>
<FormattedMessage className='user-panel-stats-item__label' id='account.posts' defaultMessage='Posts' />
</Text>
</HStack>
</Link>
)}
{account.get('followers_count') >= 0 && (
<Link to={`/@${account.get('acct')}/followers`} title={intl.formatNumber(account.get('followers_count'))}>
<HStack alignItems='center' space={1}>
<Text theme='primary' weight='bold' size='sm'>
{shortNumberFormat(account.get('followers_count'))}
</Text>
<Text weight='bold' size='sm'>
<FormattedMessage id='account.followers' defaultMessage='Followers' />
</Text>
</HStack>
</Link>
)}
{account.get('following_count') >= 0 && (
<Link to={`/@${account.get('acct')}/following`} title={intl.formatNumber(account.get('following_count'))}>
<HStack alignItems='center' space={1}>
<Text theme='primary' weight='bold' size='sm'>
{shortNumberFormat(account.get('following_count'))}
</Text>
<Text weight='bold' size='sm'>
<FormattedMessage id='account.follows' defaultMessage='Follows' />
</Text>
</HStack>
</Link>
)}
</HStack>
</Stack>
2020-03-27 13:59:38 -07:00
</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
2021-08-03 12:22:51 -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),
displayFqn: displayFqn(state),
2020-06-16 05:06:44 -07:00
});
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));