[Glitch] Fixes display names not rendering with emojis

Port 5fa765468878a0efcee58f832075df8a499bd18b to glitch-soc

Signed-off-by: Claire <claire.github-309c@sitedethib.com>
This commit is contained in:
Echo 2025-12-15 13:54:46 +01:00 committed by Claire
parent 0c852a426f
commit 56a9d62972
5 changed files with 29 additions and 25 deletions

View File

@ -25,7 +25,7 @@ function loaded() {
const initialState = JSON.parse( const initialState = JSON.parse(
propsNode.textContent, propsNode.textContent,
) as ApiAnnualReportResponse; ) as ApiAnnualReportResponse & { me?: string };
const report = initialState.annual_reports[0]; const report = initialState.annual_reports[0];
if (!report) { if (!report) {
@ -35,7 +35,10 @@ function loaded() {
// Set up store // Set up store
store.dispatch( store.dispatch(
hydrateStore({ hydrateStore({
meta: { locale: document.documentElement.lang }, meta: {
locale: document.documentElement.lang,
me: initialState.me,
},
accounts: initialState.accounts, accounts: initialState.accounts,
}), }),
); );

View File

@ -6,6 +6,7 @@ import classNames from 'classnames';
import { Avatar } from '@/flavours/glitch/components/avatar'; import { Avatar } from '@/flavours/glitch/components/avatar';
import { Button } from '@/flavours/glitch/components/button'; import { Button } from '@/flavours/glitch/components/button';
import { DisplayName } from '@/flavours/glitch/components/display_name';
import { me } from '@/flavours/glitch/initial_state'; import { me } from '@/flavours/glitch/initial_state';
import type { Account } from '@/flavours/glitch/models/account'; import type { Account } from '@/flavours/glitch/models/account';
import type { import type {
@ -137,9 +138,6 @@ export const Archetype: React.FC<{
? archetypeSelfDescriptions ? archetypeSelfDescriptions
: archetypePublicDescriptions; : archetypePublicDescriptions;
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing -- we specifically want to fallback if `display_name` is empty
const name = account?.display_name || account?.username;
return ( return (
<div <div
className={classNames(styles.box, styles.archetype)} className={classNames(styles.box, styles.archetype)}
@ -182,7 +180,9 @@ export const Archetype: React.FC<{
<FormattedMessage <FormattedMessage
id='annual_report.summary.archetype.title_public' id='annual_report.summary.archetype.title_public'
defaultMessage="{name}'s archetype" defaultMessage="{name}'s archetype"
values={{ name }} values={{
name: <DisplayName variant='simple' account={account} />,
}}
/> />
)} )}
</h2> </h2>
@ -199,7 +199,7 @@ export const Archetype: React.FC<{
<p> <p>
{isRevealed ? ( {isRevealed ? (
intl.formatMessage(descriptions[archetype], { intl.formatMessage(descriptions[archetype], {
name, name: <DisplayName variant='simple' account={account} />,
}) })
) : ( ) : (
<FormattedMessage <FormattedMessage

View File

@ -10,7 +10,6 @@ import classNames from 'classnames/bind';
import { closeModal } from '@/flavours/glitch/actions/modal'; import { closeModal } from '@/flavours/glitch/actions/modal';
import { IconButton } from '@/flavours/glitch/components/icon_button'; import { IconButton } from '@/flavours/glitch/components/icon_button';
import { LoadingIndicator } from '@/flavours/glitch/components/loading_indicator'; import { LoadingIndicator } from '@/flavours/glitch/components/loading_indicator';
import { me } from '@/flavours/glitch/initial_state';
import { import {
createAppSelector, createAppSelector,
useAppDispatch, useAppDispatch,
@ -30,9 +29,6 @@ const moduleClassNames = classNames.bind(styles);
const accountSelector = createAppSelector( const accountSelector = createAppSelector(
[(state) => state.accounts, (state) => state.annualReport.report], [(state) => state.accounts, (state) => state.annualReport.report],
(accounts, report) => { (accounts, report) => {
if (me) {
return accounts.get(me);
}
if (report?.schema_version === 2) { if (report?.schema_version === 2) {
return accounts.get(report.account_id); return accounts.get(report.account_id);
} }
@ -109,7 +105,7 @@ export const AnnualReport: FC<{ context?: 'modal' | 'standalone' }> = ({
{topHashtag && ( {topHashtag && (
<MostUsedHashtag <MostUsedHashtag
hashtag={topHashtag} hashtag={topHashtag}
name={account?.display_name} account={account}
context={context} context={context}
/> />
)} )}

View File

@ -2,15 +2,17 @@ import { FormattedMessage } from 'react-intl';
import classNames from 'classnames'; import classNames from 'classnames';
import { DisplayName } from '@/flavours/glitch/components/display_name';
import type { Account } from '@/flavours/glitch/models/account';
import type { NameAndCount } from 'flavours/glitch/models/annual_report'; import type { NameAndCount } from 'flavours/glitch/models/annual_report';
import styles from './index.module.scss'; import styles from './index.module.scss';
export const MostUsedHashtag: React.FC<{ export const MostUsedHashtag: React.FC<{
hashtag: NameAndCount; hashtag: NameAndCount;
name: string | undefined;
context: 'modal' | 'standalone'; context: 'modal' | 'standalone';
}> = ({ hashtag, name, context }) => { account?: Account;
}> = ({ hashtag, context, account }) => {
return ( return (
<div <div
className={classNames(styles.box, styles.mostUsedHashtag, styles.content)} className={classNames(styles.box, styles.mostUsedHashtag, styles.content)}
@ -25,20 +27,22 @@ export const MostUsedHashtag: React.FC<{
<div className={styles.statExtraLarge}>#{hashtag.name}</div> <div className={styles.statExtraLarge}>#{hashtag.name}</div>
<p> <p>
{context === 'modal' ? ( {context === 'modal' && (
<FormattedMessage <FormattedMessage
id='annual_report.summary.most_used_hashtag.used_count' id='annual_report.summary.most_used_hashtag.used_count'
defaultMessage='You included this hashtag in {count, plural, one {one post} other {# posts}}.' defaultMessage='You included this hashtag in {count, plural, one {one post} other {# posts}}.'
values={{ count: hashtag.count }} values={{ count: hashtag.count }}
/> />
) : ( )}
name && ( {context !== 'modal' && account && (
<FormattedMessage <FormattedMessage
id='annual_report.summary.most_used_hashtag.used_count_public' id='annual_report.summary.most_used_hashtag.used_count_public'
defaultMessage='{name} included this hashtag in {count, plural, one {one post} other {# posts}}.' defaultMessage='{name} included this hashtag in {count, plural, one {one post} other {# posts}}.'
values={{ count: hashtag.count, name }} values={{
/> count: hashtag.count,
) name: <DisplayName variant='simple' account={account} />,
}}
/>
)} )}
</p> </p>
</div> </div>

View File

@ -3,12 +3,13 @@ import type { FC } from 'react';
import { FormattedMessage } from 'react-intl'; import { FormattedMessage } from 'react-intl';
import { IconLogo } from '@/flavours/glitch/components/logo'; import { IconLogo } from '@/flavours/glitch/components/logo';
import { me } from '@/flavours/glitch/initial_state'; import { useAppSelector } from '@/flavours/glitch/store';
import { AnnualReport } from './index'; import { AnnualReport } from './index';
import classes from './shared_page.module.scss'; import classes from './shared_page.module.scss';
export const WrapstodonSharedPage: FC = () => { export const WrapstodonSharedPage: FC = () => {
const isLoggedIn = useAppSelector((state) => !!state.meta.get('me'));
return ( return (
<main className={classes.wrapper}> <main className={classes.wrapper}>
<AnnualReport /> <AnnualReport />
@ -23,7 +24,7 @@ export const WrapstodonSharedPage: FC = () => {
<a href='https://joinmastodon.org'> <a href='https://joinmastodon.org'>
<FormattedMessage id='footer.about' defaultMessage='About' /> <FormattedMessage id='footer.about' defaultMessage='About' />
</a> </a>
{!me && ( {!isLoggedIn && (
<a href='https://joinmastodon.org/servers'> <a href='https://joinmastodon.org/servers'>
<FormattedMessage <FormattedMessage
id='annual_report.shared_page.sign_up' id='annual_report.shared_page.sign_up'