format reaction count to include commas

This commit is contained in:
Sean Yesmunt 2020-10-08 12:34:48 -04:00
parent c1bd9ad6af
commit 6d4a92ad27
2 changed files with 8 additions and 2 deletions

View file

@ -3,6 +3,7 @@ import * as ICONS from 'constants/icons';
import React from 'react';
import classnames from 'classnames';
import Button from 'component/button';
import { formatNumberWithCommas } from 'util/number';
type Props = {
claim: StreamClaim,
@ -31,7 +32,7 @@ function FileReactions(props: Props) {
title={__('I like this')}
requiresAuth
className={classnames('button--file-action')}
label={String(likeCount)}
label={formatNumberWithCommas(likeCount)}
iconSize={18}
icon={ICONS.UPVOTE}
onClick={() => doReactionLike(uri)}
@ -40,7 +41,7 @@ function FileReactions(props: Props) {
requiresAuth
title={__('I dislike this')}
className={classnames('button--file-action')}
label={String(dislikeCount)}
label={formatNumberWithCommas(dislikeCount)}
iconSize={18}
icon={ICONS.DOWNVOTE}
onClick={() => doReactionDislike(uri)}

5
ui/util/number.js Normal file
View file

@ -0,0 +1,5 @@
// @flow
export function formatNumberWithCommas(num: number): string {
return num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
}