Format large numbers (#556)
parent
7171d0404e
commit
0ec98c77ef
|
@ -33,6 +33,7 @@ import {NavigationProp} from 'lib/routes/types'
|
||||||
import {isDesktopWeb} from 'platform/detection'
|
import {isDesktopWeb} from 'platform/detection'
|
||||||
import {FollowState} from 'state/models/cache/my-follows'
|
import {FollowState} from 'state/models/cache/my-follows'
|
||||||
import {shareUrl} from 'lib/sharing'
|
import {shareUrl} from 'lib/sharing'
|
||||||
|
import {formatCount} from '../util/numeric/format'
|
||||||
|
|
||||||
const BACK_HITSLOP = {left: 30, top: 30, right: 30, bottom: 30}
|
const BACK_HITSLOP = {left: 30, top: 30, right: 30, bottom: 30}
|
||||||
|
|
||||||
|
@ -364,7 +365,7 @@ const ProfileHeaderLoaded = observer(
|
||||||
style={[s.flexRow, s.mr10]}
|
style={[s.flexRow, s.mr10]}
|
||||||
onPress={onPressFollowers}>
|
onPress={onPressFollowers}>
|
||||||
<Text type="md" style={[s.bold, s.mr2, pal.text]}>
|
<Text type="md" style={[s.bold, s.mr2, pal.text]}>
|
||||||
{view.followersCount}
|
{formatCount(view.followersCount)}
|
||||||
</Text>
|
</Text>
|
||||||
<Text type="md" style={[pal.textLight]}>
|
<Text type="md" style={[pal.textLight]}>
|
||||||
{pluralize(view.followersCount, 'follower')}
|
{pluralize(view.followersCount, 'follower')}
|
||||||
|
@ -375,7 +376,7 @@ const ProfileHeaderLoaded = observer(
|
||||||
style={[s.flexRow, s.mr10]}
|
style={[s.flexRow, s.mr10]}
|
||||||
onPress={onPressFollows}>
|
onPress={onPressFollows}>
|
||||||
<Text type="md" style={[s.bold, s.mr2, pal.text]}>
|
<Text type="md" style={[s.bold, s.mr2, pal.text]}>
|
||||||
{view.followsCount}
|
{formatCount(view.followsCount)}
|
||||||
</Text>
|
</Text>
|
||||||
<Text type="md" style={[pal.textLight]}>
|
<Text type="md" style={[pal.textLight]}>
|
||||||
following
|
following
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
export const formatCount = (num: number) =>
|
||||||
|
Intl.NumberFormat('en-US', {
|
||||||
|
notation: 'compact',
|
||||||
|
maximumFractionDigits: 1,
|
||||||
|
}).format(num)
|
|
@ -39,6 +39,7 @@ import {getTabState, TabState} from 'lib/routes/helpers'
|
||||||
import {NavigationProp} from 'lib/routes/types'
|
import {NavigationProp} from 'lib/routes/types'
|
||||||
import {useNavigationTabState} from 'lib/hooks/useNavigationTabState'
|
import {useNavigationTabState} from 'lib/hooks/useNavigationTabState'
|
||||||
import {isWeb} from 'platform/detection'
|
import {isWeb} from 'platform/detection'
|
||||||
|
import {formatCount} from 'view/com/util/numeric/format'
|
||||||
|
|
||||||
export const DrawerContent = observer(() => {
|
export const DrawerContent = observer(() => {
|
||||||
const theme = useTheme()
|
const theme = useTheme()
|
||||||
|
@ -133,11 +134,11 @@ export const DrawerContent = observer(() => {
|
||||||
type="xl"
|
type="xl"
|
||||||
style={[pal.textLight, styles.profileCardFollowers]}>
|
style={[pal.textLight, styles.profileCardFollowers]}>
|
||||||
<Text type="xl-medium" style={pal.text}>
|
<Text type="xl-medium" style={pal.text}>
|
||||||
{store.me.followersCount || 0}
|
{formatCount(store.me.followersCount ?? 0)}
|
||||||
</Text>{' '}
|
</Text>{' '}
|
||||||
{pluralize(store.me.followersCount || 0, 'follower')} ·{' '}
|
{pluralize(store.me.followersCount || 0, 'follower')} ·{' '}
|
||||||
<Text type="xl-medium" style={pal.text}>
|
<Text type="xl-medium" style={pal.text}>
|
||||||
{store.me.followsCount || 0}
|
{formatCount(store.me.followsCount ?? 0)}
|
||||||
</Text>{' '}
|
</Text>{' '}
|
||||||
following
|
following
|
||||||
</Text>
|
</Text>
|
||||||
|
|
Loading…
Reference in New Issue