Add endorsed accounts to profiles in web UI (#34568)

This commit is contained in:
Eugen Rochko 2025-04-29 14:14:22 +02:00 committed by GitHub
parent b81c28e7dc
commit 79013c730d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
21 changed files with 157 additions and 113 deletions

View file

@ -11,27 +11,25 @@ interface Params {
id?: string;
}
export function useAccountId() {
export const useAccountId = () => {
const { acct, id } = useParams<Params>();
const dispatch = useAppDispatch();
const accountId = useAppSelector(
(state) =>
id ??
(state.accounts_map.get(normalizeForLookup(acct)) as string | undefined),
id ?? (acct ? state.accounts_map[normalizeForLookup(acct)] : undefined),
);
const account = useAppSelector((state) =>
accountId ? state.accounts.get(accountId) : undefined,
);
const isAccount = !!account;
const accountInStore = !!account;
const dispatch = useAppDispatch();
useEffect(() => {
if (!accountId) {
if (typeof accountId === 'undefined' && acct) {
dispatch(lookupAccount(acct));
} else if (!isAccount) {
} else if (accountId && !accountInStore) {
dispatch(fetchAccount(accountId));
}
}, [dispatch, accountId, acct, isAccount]);
}, [dispatch, accountId, acct, accountInStore]);
return accountId;
}
};

View file

@ -1,12 +1,14 @@
import { getAccountHidden } from 'mastodon/selectors/accounts';
import { useAppSelector } from 'mastodon/store';
export function useAccountVisibility(accountId?: string) {
const blockedBy = useAppSelector(
(state) => !!state.relationships.getIn([accountId, 'blocked_by'], false),
export function useAccountVisibility(accountId?: string | null) {
const blockedBy = useAppSelector((state) =>
accountId
? !!state.relationships.getIn([accountId, 'blocked_by'], false)
: false,
);
const suspended = useAppSelector(
(state) => !!state.accounts.getIn([accountId, 'suspended'], false),
const suspended = useAppSelector((state) =>
accountId ? !!state.accounts.getIn([accountId, 'suspended'], false) : false,
);
const hidden = useAppSelector((state) =>
accountId ? Boolean(getAccountHidden(state, accountId)) : false,