Rm decimals over 10k
This commit is contained in:
@@ -5,12 +5,12 @@ import {useLingui} from '@lingui/react'
|
||||
|
||||
import {useHaptics} from '#/lib/haptics'
|
||||
import {useRequireAuth} from '#/state/session'
|
||||
import {formatCount} from '#/view/com/util/numeric/format'
|
||||
import {atoms as a, useTheme} from '#/alf'
|
||||
import {Button, ButtonText} from '#/components/Button'
|
||||
import * as Dialog from '#/components/Dialog'
|
||||
import {CloseQuote_Stroke2_Corner1_Rounded as Quote} from '#/components/icons/Quote'
|
||||
import {Repost_Stroke2_Corner3_Rounded as Repost} from '#/components/icons/Repost'
|
||||
import {formatPostStatCount} from '#/components/PostControls/util'
|
||||
import {Text} from '#/components/Typography'
|
||||
import {
|
||||
PostControlButton,
|
||||
@@ -25,6 +25,7 @@ interface Props {
|
||||
onQuote: () => void
|
||||
big?: boolean
|
||||
embeddingDisabled: boolean
|
||||
compactCount?: boolean
|
||||
}
|
||||
|
||||
let RepostButton = ({
|
||||
@@ -34,6 +35,7 @@ let RepostButton = ({
|
||||
onQuote,
|
||||
big,
|
||||
embeddingDisabled,
|
||||
compactCount,
|
||||
}: Props): React.ReactNode => {
|
||||
const t = useTheme()
|
||||
const {_, i18n} = useLingui()
|
||||
@@ -86,7 +88,7 @@ let RepostButton = ({
|
||||
<PostControlButtonIcon icon={Repost} />
|
||||
{typeof repostCount !== 'undefined' && repostCount > 0 && (
|
||||
<PostControlButtonText testID="repostCount">
|
||||
{formatCount(i18n, repostCount)}
|
||||
{formatPostStatCount(i18n, repostCount, {compact: compactCount})}
|
||||
</PostControlButtonText>
|
||||
)}
|
||||
</PostControlButton>
|
||||
|
||||
@@ -24,10 +24,10 @@ import {
|
||||
ProgressGuideAction,
|
||||
useProgressGuideControls,
|
||||
} from '#/state/shell/progress-guide'
|
||||
import {formatCount} from '#/view/com/util/numeric/format'
|
||||
import * as Toast from '#/view/com/util/Toast'
|
||||
import {atoms as a, useBreakpoints} from '#/alf'
|
||||
import {Reply as Bubble} from '#/components/icons/Reply'
|
||||
import {formatPostStatCount} from '#/components/PostControls/util'
|
||||
import {BookmarkButton} from './BookmarkButton'
|
||||
import {
|
||||
PostControlButton,
|
||||
@@ -52,6 +52,7 @@ let PostControls = ({
|
||||
threadgateRecord,
|
||||
onShowLess,
|
||||
viaRepost,
|
||||
variant,
|
||||
}: {
|
||||
big?: boolean
|
||||
post: Shadow<AppBskyFeedDefs.PostView>
|
||||
@@ -66,6 +67,7 @@ let PostControls = ({
|
||||
threadgateRecord?: AppBskyFeedThreadgate.Record
|
||||
onShowLess?: (interaction: AppBskyFeedDefs.Interaction) => void
|
||||
viaRepost?: {uri: string; cid: string}
|
||||
variant?: 'compact' | 'normal' | 'large'
|
||||
}): React.ReactNode => {
|
||||
const {_, i18n} = useLingui()
|
||||
const {openComposer} = useOpenComposer()
|
||||
@@ -224,7 +226,9 @@ let PostControls = ({
|
||||
<PostControlButtonIcon icon={Bubble} />
|
||||
{typeof post.replyCount !== 'undefined' && post.replyCount > 0 && (
|
||||
<PostControlButtonText>
|
||||
{formatCount(i18n, post.replyCount)}
|
||||
{formatPostStatCount(i18n, post.replyCount, {
|
||||
compact: variant === 'compact',
|
||||
})}
|
||||
</PostControlButtonText>
|
||||
)}
|
||||
</PostControlButton>
|
||||
@@ -237,6 +241,7 @@ let PostControls = ({
|
||||
onQuote={onQuote}
|
||||
big={big}
|
||||
embeddingDisabled={Boolean(post.viewer?.embeddingDisabled)}
|
||||
compactCount={variant === 'compact'}
|
||||
/>
|
||||
</View>
|
||||
<View style={[a.flex_1, a.align_start]}>
|
||||
@@ -277,6 +282,7 @@ let PostControls = ({
|
||||
big={big}
|
||||
isLiked={Boolean(post.viewer?.like)}
|
||||
hasBeenToggled={hasLikeIconBeenToggled}
|
||||
compactCount={variant === 'compact'}
|
||||
/>
|
||||
</PostControlButton>
|
||||
</View>
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
import {type I18n} from '@lingui/core'
|
||||
|
||||
export function formatPostStatCount(
|
||||
i18n: I18n,
|
||||
count: number,
|
||||
{
|
||||
compact = false,
|
||||
}: {
|
||||
compact?: boolean
|
||||
} = {},
|
||||
): string {
|
||||
const isOver10k = count >= 10_000
|
||||
return i18n.number(count, {
|
||||
notation: 'compact',
|
||||
maximumFractionDigits: isOver10k || compact ? 0 : 1,
|
||||
// @ts-expect-error - roundingMode not in the types
|
||||
roundingMode: 'trunc',
|
||||
})
|
||||
}
|
||||
@@ -10,9 +10,9 @@ import {i18n} from '@lingui/core'
|
||||
|
||||
import {decideShouldRoll} from '#/lib/custom-animations/util'
|
||||
import {s} from '#/lib/styles'
|
||||
import {formatCount} from '#/view/com/util/numeric/format'
|
||||
import {Text} from '#/view/com/util/text/Text'
|
||||
import {atoms as a, useTheme} from '#/alf'
|
||||
import {formatPostStatCount} from '#/components/PostControls/util'
|
||||
|
||||
const animationConfig = {
|
||||
duration: 400,
|
||||
@@ -92,11 +92,13 @@ export function CountWheel({
|
||||
big,
|
||||
isLiked,
|
||||
hasBeenToggled,
|
||||
compactCount,
|
||||
}: {
|
||||
likeCount: number
|
||||
big?: boolean
|
||||
isLiked: boolean
|
||||
hasBeenToggled: boolean
|
||||
compactCount?: boolean
|
||||
}) {
|
||||
const t = useTheme()
|
||||
const shouldAnimate = !useReducedMotion() && hasBeenToggled
|
||||
@@ -109,8 +111,12 @@ export function CountWheel({
|
||||
const [key, setKey] = React.useState(0)
|
||||
const [prevCount, setPrevCount] = React.useState(likeCount)
|
||||
const prevIsLiked = React.useRef(isLiked)
|
||||
const formattedCount = formatCount(i18n, likeCount)
|
||||
const formattedPrevCount = formatCount(i18n, prevCount)
|
||||
const formattedCount = formatPostStatCount(i18n, likeCount, {
|
||||
compact: compactCount,
|
||||
})
|
||||
const formattedPrevCount = formatPostStatCount(i18n, prevCount, {
|
||||
compact: compactCount,
|
||||
})
|
||||
|
||||
React.useEffect(() => {
|
||||
if (isLiked === prevIsLiked.current) {
|
||||
|
||||
@@ -32,7 +32,6 @@ import {useSession} from '#/state/session'
|
||||
import {type OnPostSuccessData} from '#/state/shell/composer'
|
||||
import {useMergedThreadgateHiddenReplies} from '#/state/threadgate-hidden-replies'
|
||||
import {type PostSource} from '#/state/unstable-post-source'
|
||||
import {formatCount} from '#/view/com/util/numeric/format'
|
||||
import {PreviewableUserAvatar} from '#/view/com/util/UserAvatar'
|
||||
import {ThreadItemAnchorFollowButton} from '#/screens/PostThread/components/ThreadItemAnchorFollowButton'
|
||||
import {
|
||||
@@ -53,6 +52,7 @@ import {PostAlerts} from '#/components/moderation/PostAlerts'
|
||||
import {type AppModerationCause} from '#/components/Pills'
|
||||
import {Embed, PostEmbedViewContext} from '#/components/Post/Embed'
|
||||
import {PostControls} from '#/components/PostControls'
|
||||
import {formatPostStatCount} from '#/components/PostControls/util'
|
||||
import {ProfileHoverCard} from '#/components/ProfileHoverCard'
|
||||
import * as Prompt from '#/components/Prompt'
|
||||
import {RichText} from '#/components/RichText'
|
||||
@@ -434,7 +434,7 @@ const ThreadItemAnchorInner = memo(function ThreadItemAnchorInner({
|
||||
testID="repostCount-expanded"
|
||||
style={[a.text_md, t.atoms.text_contrast_medium]}>
|
||||
<Text style={[a.text_md, a.font_bold, t.atoms.text]}>
|
||||
{formatCount(i18n, post.repostCount)}
|
||||
{formatPostStatCount(i18n, post.repostCount)}
|
||||
</Text>{' '}
|
||||
<Plural
|
||||
value={post.repostCount}
|
||||
@@ -452,7 +452,7 @@ const ThreadItemAnchorInner = memo(function ThreadItemAnchorInner({
|
||||
testID="quoteCount-expanded"
|
||||
style={[a.text_md, t.atoms.text_contrast_medium]}>
|
||||
<Text style={[a.text_md, a.font_bold, t.atoms.text]}>
|
||||
{formatCount(i18n, post.quoteCount)}
|
||||
{formatPostStatCount(i18n, post.quoteCount)}
|
||||
</Text>{' '}
|
||||
<Plural
|
||||
value={post.quoteCount}
|
||||
@@ -468,7 +468,7 @@ const ThreadItemAnchorInner = memo(function ThreadItemAnchorInner({
|
||||
testID="likeCount-expanded"
|
||||
style={[a.text_md, t.atoms.text_contrast_medium]}>
|
||||
<Text style={[a.text_md, a.font_bold, t.atoms.text]}>
|
||||
{formatCount(i18n, post.likeCount)}
|
||||
{formatPostStatCount(i18n, post.likeCount)}
|
||||
</Text>{' '}
|
||||
<Plural value={post.likeCount} one="like" other="likes" />
|
||||
</Text>
|
||||
|
||||
@@ -368,6 +368,7 @@ const ThreadItemTreePostInner = memo(function ThreadItemTreePostInner({
|
||||
</View>
|
||||
)}
|
||||
<PostControls
|
||||
variant="compact"
|
||||
post={postShadow}
|
||||
record={record}
|
||||
richText={richText}
|
||||
|
||||
Reference in New Issue
Block a user