2022-05-28 09:02:04 -07:00
|
|
|
import React from 'react';
|
|
|
|
import { FormattedMessage, useIntl } from 'react-intl';
|
|
|
|
import { Link } from 'react-router-dom';
|
|
|
|
|
2022-11-15 08:00:49 -08:00
|
|
|
import StillImage from 'soapbox/components/still-image';
|
2022-12-27 03:29:01 -08:00
|
|
|
import { Avatar, HStack, Stack, Text } from 'soapbox/components/ui';
|
2022-11-15 08:00:49 -08:00
|
|
|
import VerificationBadge from 'soapbox/components/verification-badge';
|
2022-05-28 09:02:04 -07:00
|
|
|
import { useAppSelector } from 'soapbox/hooks';
|
|
|
|
import { makeGetAccount } from 'soapbox/selectors';
|
|
|
|
import { getAcct } from 'soapbox/utils/accounts';
|
|
|
|
import { shortNumberFormat } from 'soapbox/utils/numbers';
|
|
|
|
import { displayFqn } from 'soapbox/utils/state';
|
|
|
|
|
|
|
|
const getAccount = makeGetAccount();
|
|
|
|
|
|
|
|
interface IUserPanel {
|
2023-02-15 13:26:27 -08:00
|
|
|
accountId: string
|
|
|
|
action?: JSX.Element
|
|
|
|
badges?: JSX.Element[]
|
|
|
|
domain?: string
|
2022-05-28 09:02:04 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
const UserPanel: React.FC<IUserPanel> = ({ accountId, action, badges, domain }) => {
|
|
|
|
const intl = useIntl();
|
|
|
|
const account = useAppSelector((state) => getAccount(state, accountId));
|
|
|
|
const fqn = useAppSelector((state) => displayFqn(state));
|
|
|
|
|
|
|
|
if (!account) return null;
|
2023-01-11 14:45:43 -08:00
|
|
|
const displayNameHtml = { __html: account.display_name_html };
|
|
|
|
const acct = !account.acct.includes('@') && domain ? `${account.acct}@${domain}` : account.acct;
|
|
|
|
const header = account.header;
|
|
|
|
const verified = account.verified;
|
2022-05-28 09:02:04 -07:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className='relative'>
|
|
|
|
<Stack space={2}>
|
|
|
|
<Stack>
|
2023-02-01 14:13:42 -08:00
|
|
|
<div className='relative -mx-4 -mt-4 h-24 overflow-hidden bg-gray-200'>
|
2022-05-28 09:02:04 -07:00
|
|
|
{header && (
|
2022-11-22 09:33:47 -08:00
|
|
|
<StillImage src={account.header} />
|
2022-05-28 09:02:04 -07:00
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<HStack justifyContent='between'>
|
|
|
|
<Link
|
2023-01-11 14:45:43 -08:00
|
|
|
to={`/@${account.acct}`}
|
2022-05-28 09:02:04 -07:00
|
|
|
title={acct}
|
|
|
|
className='-mt-12 block'
|
|
|
|
>
|
2023-02-01 14:13:42 -08:00
|
|
|
<Avatar src={account.avatar} size={80} className='h-20 w-20 overflow-hidden bg-gray-50 ring-2 ring-white' />
|
2022-05-28 09:02:04 -07:00
|
|
|
</Link>
|
|
|
|
|
|
|
|
{action && (
|
|
|
|
<div className='mt-2'>{action}</div>
|
|
|
|
)}
|
|
|
|
</HStack>
|
|
|
|
</Stack>
|
|
|
|
|
|
|
|
<Stack>
|
2023-01-11 14:45:43 -08:00
|
|
|
<Link to={`/@${account.acct}`}>
|
2022-05-28 09:02:04 -07:00
|
|
|
<HStack space={1} alignItems='center'>
|
|
|
|
<Text size='lg' weight='bold' dangerouslySetInnerHTML={displayNameHtml} />
|
|
|
|
|
|
|
|
{verified && <VerificationBadge />}
|
|
|
|
|
|
|
|
{badges && badges.length > 0 && (
|
|
|
|
<HStack space={1} alignItems='center'>
|
|
|
|
{badges}
|
|
|
|
</HStack>
|
|
|
|
)}
|
|
|
|
</HStack>
|
|
|
|
</Link>
|
|
|
|
|
|
|
|
<Text size='sm' theme='muted'>
|
|
|
|
@{getAcct(account, fqn)}
|
|
|
|
</Text>
|
|
|
|
</Stack>
|
|
|
|
|
|
|
|
<HStack alignItems='center' space={3}>
|
2023-01-11 14:45:43 -08:00
|
|
|
{account.followers_count >= 0 && (
|
|
|
|
<Link to={`/@${account.acct}/followers`} title={intl.formatNumber(account.followers_count)}>
|
2022-05-28 09:02:04 -07:00
|
|
|
<HStack alignItems='center' space={1}>
|
|
|
|
<Text theme='primary' weight='bold' size='sm'>
|
2023-01-11 14:45:43 -08:00
|
|
|
{shortNumberFormat(account.followers_count)}
|
2022-05-28 09:02:04 -07:00
|
|
|
</Text>
|
|
|
|
<Text weight='bold' size='sm'>
|
|
|
|
<FormattedMessage id='account.followers' defaultMessage='Followers' />
|
|
|
|
</Text>
|
|
|
|
</HStack>
|
|
|
|
</Link>
|
|
|
|
)}
|
|
|
|
|
2023-01-11 14:45:43 -08:00
|
|
|
{account.following_count >= 0 && (
|
|
|
|
<Link to={`/@${account.acct}/following`} title={intl.formatNumber(account.following_count)}>
|
2022-05-28 09:02:04 -07:00
|
|
|
<HStack alignItems='center' space={1}>
|
|
|
|
<Text theme='primary' weight='bold' size='sm'>
|
2023-01-11 14:45:43 -08:00
|
|
|
{shortNumberFormat(account.following_count)}
|
2022-05-28 09:02:04 -07:00
|
|
|
</Text>
|
|
|
|
<Text weight='bold' size='sm'>
|
|
|
|
<FormattedMessage id='account.follows' defaultMessage='Follows' />
|
|
|
|
</Text>
|
|
|
|
</HStack>
|
|
|
|
</Link>
|
|
|
|
)}
|
|
|
|
</HStack>
|
|
|
|
</Stack>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default UserPanel;
|