phanpy/src/components/name-text.jsx
Lim Chee Aun 86f38ee3b8 Fix Account sheet relationship check not working when clicking from Settings page
This is because accounts from different instances have different IDs!

They're NOT unique cross-instance. So while on one instance, cannot use the account ID of the other instance to query for relationship because the ID doesn't exist on *current* instance.
2022-12-25 23:31:50 +08:00

72 lines
1.6 KiB
JavaScript

import './name-text.css';
import emojifyText from '../utils/emojify-text';
import states from '../utils/states';
import Avatar from './avatar';
function NameText({ account, showAvatar, showAcct, short, external, onClick }) {
const { acct, avatar, avatarStatic, id, url, displayName, emojis } = account;
let { username } = account;
const displayNameWithEmoji = emojifyText(displayName, emojis);
if (
!short &&
username.toLowerCase().trim() ===
(displayName || '')
.replace(/(\:(\w|\+|\-)+\:)(?=|[\!\.\?]|$)/g, '') // Remove shortcodes, regex from https://regex101.com/r/iE9uV0/1
.toLowerCase()
.trim()
) {
username = null;
}
return (
<a
class={`name-text ${short ? 'short' : ''}`}
href={url}
target={external ? '_blank' : null}
title={`@${acct}`}
onClick={(e) => {
if (external) return;
e.preventDefault();
if (onClick) return onClick(e);
states.showAccount = account;
}}
>
{showAvatar && (
<>
<Avatar url={avatar} />{' '}
</>
)}
{displayName && !short ? (
<>
<b
dangerouslySetInnerHTML={{
__html: displayNameWithEmoji,
}}
/>
{!showAcct && username && (
<>
{' '}
<i>@{username}</i>
</>
)}
</>
) : short ? (
<i>@{username}</i>
) : (
<b>@{username}</b>
)}
{showAcct && (
<>
<br />
<i>@{acct}</i>
</>
)}
</a>
);
}
export default NameText;