From 0469ca6cb4b4803303499748ae51486e273ce7bd Mon Sep 17 00:00:00 2001 From: Samuel Newman Date: Mon, 2 Sep 2024 21:04:26 +0100 Subject: [PATCH] [Embeds] Format big numbers (#5087) --- bskyembed/package.json | 2 +- bskyembed/src/components/post.tsx | 8 ++++---- bskyembed/src/utils.ts | 10 ++++++++++ bskyembed/tsconfig.json | 2 +- bskyembed/tsconfig.snippet.json | 2 +- bskyembed/yarn.lock | 8 ++++---- 6 files changed, 21 insertions(+), 11 deletions(-) diff --git a/bskyembed/package.json b/bskyembed/package.json index cb9a4621..72d2b6df 100644 --- a/bskyembed/package.json +++ b/bskyembed/package.json @@ -22,7 +22,7 @@ "eslint-plugin-simple-import-sort": "^12.0.0", "postcss": "^8.4.38", "tailwindcss": "^3.4.3", - "typescript": "^4.0.5", + "typescript": "^5.5.4", "vite": "^5.2.8", "vite-tsconfig-paths": "^4.3.2" } diff --git a/bskyembed/src/components/post.tsx b/bskyembed/src/components/post.tsx index 1d1e8f4d..4db5eeb4 100644 --- a/bskyembed/src/components/post.tsx +++ b/bskyembed/src/components/post.tsx @@ -11,7 +11,7 @@ import likeIcon from '../../assets/heart2_filled_stroke2_corner0_rounded.svg' import logo from '../../assets/logo.svg' import repostIcon from '../../assets/repost_stroke2_corner2_rounded.svg' import {CONTENT_LABELS} from '../labels' -import {getRkey, niceDate} from '../utils' +import {getRkey, niceDate, prettyNumber} from '../utils' import {Container} from './container' import {Embed} from './embed' import {Link} from './link' @@ -78,7 +78,7 @@ export function Post({thread}: Props) {

- {post.likeCount} + {prettyNumber(post.likeCount)}

)} @@ -86,7 +86,7 @@ export function Post({thread}: Props) {

- {post.repostCount} + {prettyNumber(post.repostCount)}

)} @@ -97,7 +97,7 @@ export function Post({thread}: Props) {

{post.replyCount - ? `Read ${post.replyCount} ${ + ? `Read ${prettyNumber(post.replyCount)} ${ post.replyCount > 1 ? 'replies' : 'reply' } on Bluesky` : `View on Bluesky`} diff --git a/bskyembed/src/utils.ts b/bskyembed/src/utils.ts index 1f6fd506..cfa4a525 100644 --- a/bskyembed/src/utils.ts +++ b/bskyembed/src/utils.ts @@ -16,3 +16,13 @@ export function getRkey({uri}: {uri: string}): string { const at = new AtUri(uri) return at.rkey } + +const formatter = new Intl.NumberFormat('en-US', { + notation: 'compact', + maximumFractionDigits: 1, + roundingMode: 'trunc', +}) + +export function prettyNumber(number: number) { + return formatter.format(number) +} diff --git a/bskyembed/tsconfig.json b/bskyembed/tsconfig.json index 44c516ed..b3b6055c 100644 --- a/bskyembed/tsconfig.json +++ b/bskyembed/tsconfig.json @@ -20,5 +20,5 @@ "jsxFragmentFactory": "Fragment", "downlevelIteration": true }, - "include": ["src"] + "include": ["src", "vite.config.ts"] } diff --git a/bskyembed/tsconfig.snippet.json b/bskyembed/tsconfig.snippet.json index a6b6071d..fee21964 100644 --- a/bskyembed/tsconfig.snippet.json +++ b/bskyembed/tsconfig.snippet.json @@ -6,5 +6,5 @@ "strict": true, "outDir": "dist" }, - "include": ["snippet"], + "include": ["snippet"] } diff --git a/bskyembed/yarn.lock b/bskyembed/yarn.lock index ca52dc07..3c5ef5ae 100644 --- a/bskyembed/yarn.lock +++ b/bskyembed/yarn.lock @@ -4024,10 +4024,10 @@ typed-array-length@^1.0.6: is-typed-array "^1.1.13" possible-typed-array-names "^1.0.0" -typescript@^4.0.5: - version "4.9.5" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.9.5.tgz#095979f9bcc0d09da324d58d03ce8f8374cbe65a" - integrity sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g== +typescript@^5.5.4: + version "5.5.4" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.5.4.tgz#d9852d6c82bad2d2eda4fd74a5762a8f5909e9ba" + integrity sha512-Mtq29sKDAEYP7aljRgtPOpTvOfbwRWlS6dPRzwjdE+C0R4brX/GUyhHSecbHMFLNBLcJIPt9nl9yG5TZ1weH+Q== uint8arrays@3.0.0: version "3.0.0"