Skip to content

Commit 0c4b908

Browse files
authored
Simplify post number formatting (#8978)
* revert number formatting change * use formatPostStatCount in repost web
1 parent 457cd3d commit 0c4b908

File tree

2 files changed

+6
-29
lines changed

2 files changed

+6
-29
lines changed

src/components/PostControls/RepostButton.web.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import {useLingui} from '@lingui/react'
44
import {useRequireAuth} from '#/state/session'
55
import {useSession} from '#/state/session'
66
import {EventStopper} from '#/view/com/util/EventStopper'
7-
import {formatCount} from '#/view/com/util/numeric/format'
87
import {useTheme} from '#/alf'
98
import {CloseQuote_Stroke2_Corner1_Rounded as Quote} from '#/components/icons/Quote'
109
import {Repost_Stroke2_Corner2_Rounded as Repost} from '#/components/icons/Repost'
@@ -14,6 +13,7 @@ import {
1413
PostControlButtonIcon,
1514
PostControlButtonText,
1615
} from './PostControlButton'
16+
import {useFormatPostStatCount} from './util'
1717

1818
interface Props {
1919
isReposted: boolean
@@ -33,9 +33,10 @@ export const RepostButton = ({
3333
embeddingDisabled,
3434
}: Props) => {
3535
const t = useTheme()
36-
const {_, i18n} = useLingui()
36+
const {_} = useLingui()
3737
const {hasSession} = useSession()
3838
const requireAuth = useRequireAuth()
39+
const formatPostStatCount = useFormatPostStatCount()
3940

4041
return hasSession ? (
4142
<EventStopper onKeyDown={false}>
@@ -53,7 +54,7 @@ export const RepostButton = ({
5354
<PostControlButtonIcon icon={Repost} />
5455
{typeof repostCount !== 'undefined' && repostCount > 0 && (
5556
<PostControlButtonText testID="repostCount">
56-
{formatCount(i18n, repostCount)}
57+
{formatPostStatCount(repostCount)}
5758
</PostControlButtonText>
5859
)}
5960
</PostControlButton>
@@ -105,7 +106,7 @@ export const RepostButton = ({
105106
<PostControlButtonIcon icon={Repost} />
106107
{typeof repostCount !== 'undefined' && repostCount > 0 && (
107108
<PostControlButtonText testID="repostCount">
108-
{formatCount(i18n, repostCount)}
109+
{formatPostStatCount(repostCount)}
109110
</PostControlButtonText>
110111
)}
111112
</PostControlButton>

src/components/PostControls/util.ts

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import {useCallback} from 'react'
2-
import {msg} from '@lingui/macro'
32
import {useLingui} from '@lingui/react'
43

54
/**
@@ -12,36 +11,13 @@ export function useFormatPostStatCount() {
1211

1312
return useCallback(
1413
(postStatCount: number) => {
15-
const isOver1k = postStatCount >= 1_000
1614
const isOver10k = postStatCount >= 10_000
17-
const isOver1M = postStatCount >= 1_000_000
18-
const formatted = i18n.number(postStatCount, {
15+
return i18n.number(postStatCount, {
1916
notation: 'compact',
2017
maximumFractionDigits: isOver10k ? 0 : 1,
2118
// @ts-expect-error - roundingMode not in the types
2219
roundingMode: 'trunc',
2320
})
24-
const count = formatted.replace(/\D+$/g, '')
25-
26-
if (isOver1M) {
27-
return i18n._(
28-
msg({
29-
message: `${count}M`,
30-
comment:
31-
'For post statistics. Indicates a number in the millions. Please use the shortest format appropriate for your language.',
32-
}),
33-
)
34-
} else if (isOver1k) {
35-
return i18n._(
36-
msg({
37-
message: `${count}K`,
38-
comment:
39-
'For post statistics. Indicates a number in the thousands. Please use the shortest format appropriate for your language.',
40-
}),
41-
)
42-
} else {
43-
return count
44-
}
4521
},
4622
[i18n],
4723
)

0 commit comments

Comments
 (0)