From e303c89e4d97235411c405c388034a87acd7fdce Mon Sep 17 00:00:00 2001 From: diondiondion Date: Fri, 27 Mar 2026 17:13:07 +0100 Subject: [PATCH] Refactor `NumberFields` to standalone component (#38455) --- .../components/number_fields/index.tsx | 40 ++++++++ .../number_fields/styles.module.scss | 32 +++++++ app/javascript/mastodon/components/router.tsx | 2 + .../components/number_fields.tsx | 96 +++++++++---------- .../components/redesign.module.scss | 31 ------ 5 files changed, 120 insertions(+), 81 deletions(-) create mode 100644 app/javascript/mastodon/components/number_fields/index.tsx create mode 100644 app/javascript/mastodon/components/number_fields/styles.module.scss diff --git a/app/javascript/mastodon/components/number_fields/index.tsx b/app/javascript/mastodon/components/number_fields/index.tsx new file mode 100644 index 0000000000..36e99725c7 --- /dev/null +++ b/app/javascript/mastodon/components/number_fields/index.tsx @@ -0,0 +1,40 @@ +import { NavLink } from 'react-router-dom'; + +import type { MastodonLocationDescriptor } from 'mastodon/components/router'; + +import classes from './styles.module.scss'; + +interface WrapperProps { + children: React.ReactNode; +} + +export const NumberFields: React.FC = ({ children }) => { + return ; +}; + +interface ItemProps { + label: React.ReactNode; + hint?: string; + link?: MastodonLocationDescriptor; + children: React.ReactNode; +} + +export const NumberFieldsItem: React.FC = ({ + label, + hint, + link, + children, +}) => { + return ( +
  • + {label} + {link ? ( + + {children} + + ) : ( + {children} + )} +
  • + ); +}; diff --git a/app/javascript/mastodon/components/number_fields/styles.module.scss b/app/javascript/mastodon/components/number_fields/styles.module.scss new file mode 100644 index 0000000000..085bd5051d --- /dev/null +++ b/app/javascript/mastodon/components/number_fields/styles.module.scss @@ -0,0 +1,32 @@ +.list { + display: flex; + flex-wrap: wrap; + margin: 8px 0; + padding: 0; + gap: 4px 20px; + font-size: 13px; + color: var(--color-text-secondary); +} + +.item { + @container (width < 420px) { + flex: 1 1 0px; + } + + a, + strong { + display: block; + font-weight: 600; + color: var(--color-text-primary); + font-size: 15px; + } + + a { + padding: 0; + + &:hover, + &:focus { + text-decoration: underline; + } + } +} diff --git a/app/javascript/mastodon/components/router.tsx b/app/javascript/mastodon/components/router.tsx index 1c251d6abc..bd6e4b568f 100644 --- a/app/javascript/mastodon/components/router.tsx +++ b/app/javascript/mastodon/components/router.tsx @@ -26,6 +26,8 @@ export type LocationState = MastodonLocationState | null | undefined; export type MastodonLocation = ReturnType>; +export type MastodonLocationDescriptor = LocationDescriptor; + type HistoryPath = Path | LocationDescriptor; export const browserHistory = createBrowserHistory(); diff --git a/app/javascript/mastodon/features/account_timeline/components/number_fields.tsx b/app/javascript/mastodon/features/account_timeline/components/number_fields.tsx index 3494718fbf..0fa805ac6b 100644 --- a/app/javascript/mastodon/features/account_timeline/components/number_fields.tsx +++ b/app/javascript/mastodon/features/account_timeline/components/number_fields.tsx @@ -3,7 +3,6 @@ import type { FC } from 'react'; import { FormattedMessage, useIntl } from 'react-intl'; -import classNames from 'classnames'; import { NavLink } from 'react-router-dom'; import { @@ -12,13 +11,15 @@ import { StatusesCounter, } from '@/mastodon/components/counters'; import { FormattedDateWrapper } from '@/mastodon/components/formatted_date'; +import { + NumberFields, + NumberFieldsItem, +} from '@/mastodon/components/number_fields'; import { ShortNumber } from '@/mastodon/components/short_number'; import { useAccount } from '@/mastodon/hooks/useAccount'; import { isRedesignEnabled } from '../common'; -import classes from './redesign.module.scss'; - const LegacyNumberFields: FC<{ accountId: string }> = ({ accountId }) => { const intl = useIntl(); const account = useAccount(accountId); @@ -77,56 +78,51 @@ const RedesignNumberFields: FC<{ accountId: string }> = ({ accountId }) => { } return ( -
      -
    • - - - - -
    • + + } + hint={intl.formatNumber(account.statuses_count)} + > + + -
    • - - - - -
    • + + } + hint={intl.formatNumber(account.followers_count)} + link={`/@${account.acct}/followers`} + > + + -
    • - - - - -
    • + + } + hint={intl.formatNumber(account.following_count)} + link={`/@${account.acct}/following`} + > + + -
    • - - - {createdThisYear ? ( - - ) : ( - - )} - -
    • -
    + + } + hint={intl.formatDate(account.created_at)} + > + {createdThisYear ? ( + + ) : ( + + )} + + ); }; diff --git a/app/javascript/mastodon/features/account_timeline/components/redesign.module.scss b/app/javascript/mastodon/features/account_timeline/components/redesign.module.scss index 40fdc5cfa8..391a6ac7fe 100644 --- a/app/javascript/mastodon/features/account_timeline/components/redesign.module.scss +++ b/app/javascript/mastodon/features/account_timeline/components/redesign.module.scss @@ -312,37 +312,6 @@ svg.badgeIcon { } } -.fieldNumbersWrapper { - display: flex; - font-size: 13px; - padding: 0; - margin: 8px 0; - gap: 20px; - - li { - @container (width < 420px) { - flex: 1 1 0px; - } - } - - a, - strong { - display: block; - font-weight: 600; - color: var(--color-text-primary); - font-size: 15px; - } - - a { - padding: 0; - - &:hover, - &:focus { - text-decoration: underline; - } - } -} - .modalCloseButton { padding: 8px; border-radius: 50%;