phanpy/src/components/account-block.jsx

165 lines
3.8 KiB
React
Raw Normal View History

2023-02-12 14:29:03 +03:00
import './account-block.css';
2023-09-03 14:48:36 +03:00
// import { useNavigate } from 'react-router-dom';
import enhanceContent from '../utils/enhance-content';
import niceDateTime from '../utils/nice-date-time';
2023-02-12 14:29:03 +03:00
import states from '../utils/states';
import Avatar from './avatar';
import EmojiText from './emoji-text';
import Icon from './icon';
2023-02-12 14:29:03 +03:00
function AccountBlock({
skeleton,
account,
avatarSize = 'xl',
2023-11-12 06:01:44 +03:00
useAvatarStatic = false,
2023-02-12 14:29:03 +03:00
instance,
external,
internal,
2023-02-12 14:29:03 +03:00
onClick,
showActivity = false,
showStats = false,
2023-09-03 14:48:36 +03:00
accountInstance,
hideDisplayName = false,
2023-02-12 14:29:03 +03:00
}) {
if (skeleton) {
return (
<div class="account-block skeleton">
<Avatar size={avatarSize} />
<span>
<b></b>
<br />
<span class="account-block-acct">@</span>
2023-02-12 14:29:03 +03:00
</span>
</div>
);
}
2023-09-03 14:48:36 +03:00
// const navigate = useNavigate();
const {
id,
acct,
avatar,
avatarStatic,
displayName,
username,
emojis,
url,
statusesCount,
lastStatusAt,
2023-04-10 19:26:43 +03:00
bot,
fields,
note,
2023-08-07 16:26:56 +03:00
group,
} = account;
2023-09-03 14:48:36 +03:00
let [_, acct1, acct2] = acct.match(/([^@]+)(@.+)/i) || [, acct];
if (accountInstance) {
acct2 = `@${accountInstance}`;
}
2023-02-12 14:29:03 +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);
if (internal) {
2023-09-03 14:48:36 +03:00
// navigate(`/${instance}/a/${id}`);
location.hash = `/${instance}/a/${id}`;
} else {
states.showAccount = {
account,
instance,
};
}
2023-02-12 14:29:03 +03:00
}}
>
2023-11-12 06:01:44 +03:00
<Avatar
url={useAvatarStatic ? avatarStatic : avatar || avatarStatic}
size={avatarSize}
squircle={bot}
/>
2023-11-02 12:38:38 +03:00
<span class="account-block-content">
2023-09-03 14:48:36 +03:00
{!hideDisplayName && (
<>
{displayName ? (
<b>
<EmojiText text={displayName} emojis={emojis} />
</b>
) : (
<b>{username}</b>
)}
<br />
</>
2023-02-12 14:29:03 +03:00
)}
<span class="account-block-acct">
@{acct1}
<wbr />
{acct2}
</span>
{showActivity && (
<>
<br />
<small class="last-status-at insignificant">
Posts: {statusesCount}
{!!lastStatusAt && (
<>
{' '}
&middot; Last posted:{' '}
{niceDateTime(lastStatusAt, {
hideTime: true,
})}
</>
)}
</small>
</>
)}
{showStats && (
<div class="account-block-stats">
<div
class="short-desc"
dangerouslySetInnerHTML={{
__html: enhanceContent(note, { emojis }),
}}
/>
{bot && (
<>
<span class="tag">
<Icon icon="bot" /> Automated
</span>
</>
)}
2023-08-07 16:26:56 +03:00
{!!group && (
<>
<span class="tag">
<Icon icon="group" /> Group
</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;