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-02-12 14:29:03 +03:00
|
|
|
import emojifyText from '../utils/emojify-text';
|
2023-03-07 17:36:12 +03:00
|
|
|
import niceDateTime from '../utils/nice-date-time';
|
2023-02-12 14:29:03 +03:00
|
|
|
import states from '../utils/states';
|
|
|
|
|
|
|
|
import Avatar from './avatar';
|
|
|
|
|
|
|
|
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-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,
|
|
|
|
} = account;
|
2023-02-12 14:29:03 +03:00
|
|
|
const displayNameWithEmoji = emojifyText(displayName, emojis);
|
2023-03-11 09:05:56 +03:00
|
|
|
const [_, acct1, acct2] = acct.match(/([^@]+)(@.+)/i) || [, acct];
|
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
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Avatar url={avatar} size={avatarSize} />
|
|
|
|
<span>
|
|
|
|
{displayName ? (
|
|
|
|
<b
|
|
|
|
dangerouslySetInnerHTML={{
|
|
|
|
__html: displayNameWithEmoji,
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
) : (
|
|
|
|
<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-02-12 14:29:03 +03:00
|
|
|
</span>
|
|
|
|
</a>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default AccountBlock;
|