2023-02-12 14:29:03 +03:00
|
|
|
import './account-block.css';
|
|
|
|
|
2023-03-11 09:05:56 +03:00
|
|
|
import { useNavigate } from 'react-router-dom';
|
|
|
|
|
2023-07-02 13:02:30 +03:00
|
|
|
import enhanceContent from '../utils/enhance-content';
|
2023-03-07 17:36:12 +03:00
|
|
|
import niceDateTime from '../utils/nice-date-time';
|
2023-07-02 13:02:30 +03:00
|
|
|
import shortenNumber from '../utils/shorten-number';
|
2023-02-12 14:29:03 +03:00
|
|
|
import states from '../utils/states';
|
|
|
|
|
|
|
|
import Avatar from './avatar';
|
2023-06-14 12:37:41 +03:00
|
|
|
import EmojiText from './emoji-text';
|
2023-07-02 13:02:30 +03:00
|
|
|
import Icon from './icon';
|
2023-02-12 14:29:03 +03:00
|
|
|
|
|
|
|
function AccountBlock({
|
|
|
|
skeleton,
|
|
|
|
account,
|
|
|
|
avatarSize = 'xl',
|
|
|
|
instance,
|
|
|
|
external,
|
2023-03-11 09:05:56 +03:00
|
|
|
internal,
|
2023-02-12 14:29:03 +03:00
|
|
|
onClick,
|
2023-03-07 17:36:12 +03:00
|
|
|
showActivity = false,
|
2023-07-02 13:02:30 +03:00
|
|
|
showStats = false,
|
2023-02-12 14:29:03 +03:00
|
|
|
}) {
|
|
|
|
if (skeleton) {
|
|
|
|
return (
|
|
|
|
<div class="account-block skeleton">
|
|
|
|
<Avatar size={avatarSize} />
|
|
|
|
<span>
|
|
|
|
<b>████████</b>
|
|
|
|
<br />
|
2023-03-11 09:05:56 +03:00
|
|
|
<span class="account-block-acct">@██████</span>
|
2023-02-12 14:29:03 +03:00
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-03-11 09:05:56 +03:00
|
|
|
const navigate = useNavigate();
|
|
|
|
|
2023-03-07 17:36:12 +03:00
|
|
|
const {
|
2023-03-11 09:05:56 +03:00
|
|
|
id,
|
2023-03-07 17:36:12 +03:00
|
|
|
acct,
|
|
|
|
avatar,
|
|
|
|
avatarStatic,
|
|
|
|
displayName,
|
|
|
|
username,
|
|
|
|
emojis,
|
|
|
|
url,
|
|
|
|
statusesCount,
|
|
|
|
lastStatusAt,
|
2023-04-10 19:26:43 +03:00
|
|
|
bot,
|
2023-07-02 13:02:30 +03:00
|
|
|
fields,
|
|
|
|
note,
|
2023-03-07 17:36:12 +03:00
|
|
|
} = account;
|
2023-03-11 09:05:56 +03:00
|
|
|
const [_, acct1, acct2] = acct.match(/([^@]+)(@.+)/i) || [, acct];
|
2023-02-12 14:29:03 +03:00
|
|
|
|
2023-07-02 13:02:30 +03:00
|
|
|
const verifiedField = fields?.find((f) => !!f.verifiedAt && !!f.value);
|
|
|
|
|
2023-02-12 14:29:03 +03:00
|
|
|
return (
|
|
|
|
<a
|
|
|
|
class="account-block"
|
|
|
|
href={url}
|
|
|
|
target={external ? '_blank' : null}
|
|
|
|
title={`@${acct}`}
|
|
|
|
onClick={(e) => {
|
|
|
|
if (external) return;
|
|
|
|
e.preventDefault();
|
|
|
|
if (onClick) return onClick(e);
|
2023-03-11 09:05:56 +03:00
|
|
|
if (internal) {
|
|
|
|
navigate(`/${instance}/a/${id}`);
|
|
|
|
} else {
|
|
|
|
states.showAccount = {
|
|
|
|
account,
|
|
|
|
instance,
|
|
|
|
};
|
|
|
|
}
|
2023-02-12 14:29:03 +03:00
|
|
|
}}
|
|
|
|
>
|
2023-04-10 19:26:43 +03:00
|
|
|
<Avatar url={avatar} size={avatarSize} squircle={bot} />
|
2023-02-12 14:29:03 +03:00
|
|
|
<span>
|
|
|
|
{displayName ? (
|
2023-06-14 12:37:41 +03:00
|
|
|
<b>
|
|
|
|
<EmojiText text={displayName} emojis={emojis} />
|
|
|
|
</b>
|
2023-02-12 14:29:03 +03:00
|
|
|
) : (
|
|
|
|
<b>{username}</b>
|
|
|
|
)}
|
2023-03-11 09:05:56 +03:00
|
|
|
<br />
|
|
|
|
<span class="account-block-acct">
|
|
|
|
@{acct1}
|
|
|
|
<wbr />
|
|
|
|
{acct2}
|
|
|
|
</span>
|
2023-03-07 17:36:12 +03:00
|
|
|
{showActivity && (
|
|
|
|
<>
|
|
|
|
<br />
|
|
|
|
<small class="last-status-at insignificant">
|
|
|
|
Posts: {statusesCount}
|
|
|
|
{!!lastStatusAt && (
|
|
|
|
<>
|
|
|
|
{' '}
|
|
|
|
· Last posted:{' '}
|
|
|
|
{niceDateTime(lastStatusAt, {
|
|
|
|
hideTime: true,
|
|
|
|
})}
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</small>
|
|
|
|
</>
|
|
|
|
)}
|
2023-07-02 13:02:30 +03:00
|
|
|
{showStats && (
|
|
|
|
<div class="account-block-stats">
|
|
|
|
<div
|
|
|
|
class="short-desc"
|
|
|
|
dangerouslySetInnerHTML={{
|
|
|
|
__html: enhanceContent(note, { emojis }),
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
{bot && (
|
|
|
|
<>
|
|
|
|
<span class="tag">
|
|
|
|
<Icon icon="bot" /> Automated
|
|
|
|
</span>
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
{!!verifiedField && (
|
|
|
|
<span class="verified-field ib">
|
|
|
|
<Icon icon="check-circle" size="s" />{' '}
|
|
|
|
<span
|
|
|
|
dangerouslySetInnerHTML={{
|
|
|
|
__html: enhanceContent(verifiedField.value, { emojis }),
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</span>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
)}
|
2023-02-12 14:29:03 +03:00
|
|
|
</span>
|
|
|
|
</a>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default AccountBlock;
|