From 22c5aa4da4e8835f2694e1590c27b2e5783d3cc4 Mon Sep 17 00:00:00 2001 From: Samuel Newman Date: Wed, 19 Jun 2024 22:21:02 +0100 Subject: Truncate post metrics and fix truncation on native (#4575) * truncate post counts * add numberformat polyfill * Fix perf * Simplify type shenanigans * Bump versions to remove dupes --------- Co-authored-by: Dan Abramov --- src/locale/i18n.ts | 8 +++-- src/view/com/util/post-ctrls/PostCtrls.tsx | 5 +-- src/view/com/util/post-ctrls/RepostButton.tsx | 3 +- src/view/com/util/post-ctrls/RepostButton.web.tsx | 37 ++++++++++++----------- 4 files changed, 31 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/locale/i18n.ts b/src/locale/i18n.ts index baec4b8a2..332b9309a 100644 --- a/src/locale/i18n.ts +++ b/src/locale/i18n.ts @@ -1,6 +1,10 @@ -import '@formatjs/intl-locale/polyfill' -import '@formatjs/intl-pluralrules/polyfill-force' // Don't remove -force because detection is very slow +// Don't remove -force from these because detection is VERY slow on low-end Android. +// https://github.com/formatjs/formatjs/issues/4463#issuecomment-2176070577 +import '@formatjs/intl-locale/polyfill-force' +import '@formatjs/intl-pluralrules/polyfill-force' +import '@formatjs/intl-numberformat/polyfill-force' import '@formatjs/intl-pluralrules/locale-data/en' +import '@formatjs/intl-numberformat/locale-data/en' import {useEffect} from 'react' import {i18n} from '@lingui/core' diff --git a/src/view/com/util/post-ctrls/PostCtrls.tsx b/src/view/com/util/post-ctrls/PostCtrls.tsx index c0e743db4..55fb4a334 100644 --- a/src/view/com/util/post-ctrls/PostCtrls.tsx +++ b/src/view/com/util/post-ctrls/PostCtrls.tsx @@ -39,6 +39,7 @@ import { } from '#/components/icons/Heart2' import * as Prompt from '#/components/Prompt' import {PostDropdownBtn} from '../forms/PostDropdownBtn' +import {formatCount} from '../numeric/format' import {Text} from '../text/Text' import {RepostButton} from './RepostButton' @@ -226,7 +227,7 @@ let PostCtrls = ({ big ? a.text_md : {fontSize: 15}, a.user_select_none, ]}> - {post.replyCount} + {formatCount(post.replyCount)} ) : undefined} @@ -278,7 +279,7 @@ let PostCtrls = ({ : defaultCtrlColor, ], ]}> - {post.likeCount} + {formatCount(post.likeCount)} ) : undefined} diff --git a/src/view/com/util/post-ctrls/RepostButton.tsx b/src/view/com/util/post-ctrls/RepostButton.tsx index 81e89d42d..10bc369b8 100644 --- a/src/view/com/util/post-ctrls/RepostButton.tsx +++ b/src/view/com/util/post-ctrls/RepostButton.tsx @@ -12,6 +12,7 @@ import * as Dialog from '#/components/Dialog' import {CloseQuote_Stroke2_Corner1_Rounded as Quote} from '#/components/icons/Quote' import {Repost_Stroke2_Corner2_Rounded as Repost} from '#/components/icons/Repost' import {Text} from '#/components/Typography' +import {formatCount} from '../numeric/format' interface Props { isReposted: boolean @@ -76,7 +77,7 @@ let RepostButton = ({ big ? a.text_md : {fontSize: 15}, isReposted && a.font_bold, ]}> - {repostCount} + {formatCount(repostCount)} ) : undefined} diff --git a/src/view/com/util/post-ctrls/RepostButton.web.tsx b/src/view/com/util/post-ctrls/RepostButton.web.tsx index 089898141..17ab736ce 100644 --- a/src/view/com/util/post-ctrls/RepostButton.web.tsx +++ b/src/view/com/util/post-ctrls/RepostButton.web.tsx @@ -12,6 +12,7 @@ import {Repost_Stroke2_Corner2_Rounded as Repost} from '#/components/icons/Repos import * as Menu from '#/components/Menu' import {Text} from '#/components/Typography' import {EventStopper} from '../EventStopper' +import {formatCount} from '../numeric/format' interface Props { isReposted: boolean @@ -115,20 +116,22 @@ const RepostInner = ({ color: {color: string} repostCount?: number big?: boolean -}) => ( - - - {typeof repostCount !== 'undefined' && repostCount > 0 ? ( - - {repostCount} - - ) : undefined} - -) +}) => { + return ( + + + {typeof repostCount !== 'undefined' && repostCount > 0 ? ( + + {formatCount(repostCount)} + + ) : undefined} + + ) +} -- cgit 1.4.1