fix: format many voters as human readable number

zio/stable
Daniel Roe 2022-12-08 11:56:23 +01:00
parent 2fed89be9d
commit be68912226
No known key found for this signature in database
GPG Key ID: 22D5008E4F5D9B55
2 changed files with 3 additions and 2 deletions

View File

@ -13,6 +13,7 @@ function toPercentage(num: number) {
const timeAgoOptions = useTimeAgoOptions()
const expiredTimeAgo = useTimeAgo(poll.expiresAt!, timeAgoOptions)
const expiredTimeFormatted = useFormattedDateTime(poll.expiresAt!)
const { formatHumanReadableNumber } = useHumanReadableNumber()
const masto = useMasto()
async function vote(e: Event) {
@ -57,7 +58,7 @@ async function vote(e: Event) {
</div>
</template>
<div text-sm>
{{ $t('status.poll.count', poll.votersCount ?? 0) }}
{{ $t('status.poll.count', formatHumanReadableNumber(poll.votersCount ?? 0)) }}
&middot;
<CommonTooltip :content="expiredTimeFormatted" class="inline-block" placement="right">
<time :datetime="poll.expiresAt!">{{ $t(poll.expired ? 'status.poll.finished' : 'status.poll.ends', [expiredTimeAgo]) }}</time>

View File

@ -3,7 +3,7 @@ import type { MaybeComputedRef, UseTimeAgoOptions } from '@vueuse/core'
const formatter = Intl.NumberFormat()
export const humanReadableNumber = (
const humanReadableNumber = (
num: number,
{ k, m }: { k: string; m: string } = { k: 'K', m: 'M' },
useFormatter: Intl.NumberFormat = formatter,