Hide roles if is self for NameText

Also a quick refactor
pull/1274/merge
Lim Chee Aun 2025-09-18 09:49:53 +08:00
rodzic cb7a8e1d7d
commit c876f3c2b6
4 zmienionych plików z 53 dodań i 61 usunięć

Wyświetl plik

@ -4,7 +4,6 @@ import { Plural, Trans, useLingui } from '@lingui/react/macro';
// import { useNavigate } from 'react-router-dom';
import enhanceContent from '../utils/enhance-content';
import getDomain from '../utils/get-domain';
import niceDateTime from '../utils/nice-date-time';
import shortenNumber from '../utils/shorten-number';
import states from '../utils/states';
@ -12,6 +11,7 @@ import states from '../utils/states';
import Avatar from './avatar';
import EmojiText from './emoji-text';
import Icon from './icon';
import RolesTags from './roles-tags';
function AccountBlock({
skeleton,
@ -74,8 +74,6 @@ function AccountBlock({
acct2 = `@${accountInstance}`;
}
const parsedAccountInstance = getDomain(url);
const verifiedField = fields?.find((f) => !!f.verifiedAt && !!f.value);
const excludedRelationship = {};
@ -142,22 +140,7 @@ function AccountBlock({
</>
)}
</span>
{roles?.map((role) => (
<>
{' '}
<span class="tag collapsed">
{role.name}
{!!parsedAccountInstance && (
<>
{' '}
<span class="more-insignificant">
{parsedAccountInstance}
</span>
</>
)}
</span>
</>
))}
<RolesTags roles={roles} accountUrl={url} />
{showActivity && (
<div class="account-block-stats">
<Trans>Posts: {shortenNumber(statusesCount)}</Trans>

Wyświetl plik

@ -10,6 +10,7 @@ import states from '../utils/states';
import Avatar from './avatar';
import EmojiText from './emoji-text';
import RolesTags from './roles-tags';
const nameCollator = mem((locale) => {
const options = {
@ -118,22 +119,12 @@ function NameText({
<>
{' '}
<i class="bidi-isolate">@{username}</i>
{roles?.map((role) => (
<>
{' '}
<span class="tag collapsed">
{role.name}
{!!accountInstance && (
<>
{' '}
<span class="more-insignificant">
{accountInstance}
</span>
</>
)}
</span>
</>
))}
<RolesTags
roles={roles}
accountId={id}
accountUrl={url}
hideSelf
/>
</>
)}
</>
@ -150,20 +141,7 @@ function NameText({
{acct1}
{!!acct2 && <span class="ib">{acct2}</span>}
</i>
{roles?.map((role) => (
<>
{' '}
<span class="tag collapsed">
{role.name}
{!!accountInstance && (
<>
{' '}
<span class="more-insignificant">{accountInstance}</span>
</>
)}
</span>
</>
))}
<RolesTags roles={roles} accountUrl={url} />
</>
)}
</a>

Wyświetl plik

@ -0,0 +1,31 @@
import getDomain from '../utils/get-domain';
import { getCurrentAccountID } from '../utils/store-utils';
function RolesTags({ roles, accountId, accountUrl, hideSelf = false }) {
if (!roles?.length) return null;
const isSelf = accountId && accountId === getCurrentAccountID();
if (!accountId && hideSelf) {
console.warn('accountId is required if hideSelf is true');
}
if (hideSelf && isSelf) return null;
const parsedAccountInstance = getDomain(accountUrl);
return roles?.map((role) => (
<>
{' '}
<span class="tag collapsed">
{role.name}
{!!parsedAccountInstance && (
<>
{' '}
<span class="more-insignificant">{parsedAccountInstance}</span>
</>
)}
</span>
</>
));
}
export default RolesTags;

24
src/locales/en.po wygenerowano
Wyświetl plik

@ -13,62 +13,62 @@ msgstr ""
"Language-Team: \n"
"Plural-Forms: \n"
#: src/components/account-block.jsx:141
#: src/components/account-block.jsx:139
msgid "Locked"
msgstr ""
#. placeholder {0}: shortenNumber(statusesCount)
#: src/components/account-block.jsx:163
#: src/components/account-block.jsx:146
msgid "Posts: {0}"
msgstr ""
#. placeholder {0}: niceDateTime(lastStatusAt, { hideTime: true, })
#: src/components/account-block.jsx:168
#: src/components/account-block.jsx:151
msgid "Last posted: {0}"
msgstr ""
#: src/components/account-block.jsx:183
#: src/components/account-block.jsx:166
#: src/components/account-info.jsx:670
msgid "Automated"
msgstr ""
#: src/components/account-block.jsx:190
#: src/components/account-block.jsx:173
#: src/components/account-info.jsx:675
#: src/components/status.jsx:529
msgid "Group"
msgstr ""
#: src/components/account-block.jsx:200
#: src/components/account-block.jsx:183
msgid "Mutual"
msgstr ""
#: src/components/account-block.jsx:204
#: src/components/account-block.jsx:187
#: src/components/related-actions.jsx:882
msgid "Requested"
msgstr ""
#: src/components/account-block.jsx:208
#: src/components/account-block.jsx:191
#: src/components/related-actions.jsx:873
msgid "Following"
msgstr ""
#: src/components/account-block.jsx:212
#: src/components/account-block.jsx:195
#: src/components/related-actions.jsx:182
msgid "Follows you"
msgstr ""
#: src/components/account-block.jsx:220
#: src/components/account-block.jsx:203
msgid "{followersCount, plural, one {# follower} other {# followers}}"
msgstr ""
#: src/components/account-block.jsx:229
#: src/components/account-block.jsx:212
#: src/components/account-info.jsx:718
msgid "Verified"
msgstr ""
#. placeholder {0}: niceDateTime(createdAt, { hideTime: true, })
#. placeholder {0}: niceDateTime(createdAt, { hideTime: true, })
#: src/components/account-block.jsx:244
#: src/components/account-block.jsx:227
#: src/components/account-info.jsx:857
msgid "Joined <0>{0}</0>"
msgstr ""