about summary refs log tree commit diff
path: root/src/components/PostControls/util.ts
diff options
context:
space:
mode:
authorEric Bailey <git@esb.lol>2025-09-04 17:30:15 -0500
committerGitHub <noreply@github.com>2025-09-04 17:30:15 -0500
commit535d4d6cf74cfb49a70804bccb4de1613d2ac09c (patch)
tree78198de5712398e5a9a4b43ec69b254f81081442 /src/components/PostControls/util.ts
parent04b869714e512ed29653892d45dab806396824e1 (diff)
downloadvoidsky-535d4d6cf74cfb49a70804bccb4de1613d2ac09c.tar.zst
📓 Bookmarks (#8976)
* Add button to controls, respace

* Hook up shadow and mutation

* Add Bookmarks screen

* Build out Bookmarks screen

* Handle removals via shadow

* Use truncateAndInvalidate strategy

* Add empty state

* Add toasts

* Add undo buttons to toasts

* Stage NUX, needs image

* Finesse post controls

* New reply icon

* Use curvier variant of repost icon

* Prevent layout shift with align_start

* Update api pkg

* Swap in new image

* Limit spacing on desktop

* Rm decimals over 10k

* Better optimistic adding/removing

* Add metrics

* Comment

* Remove unused code block

* Remove debug limit

* Fork shadow for web/native

* Tweak alt

* add preventExpansion: true

* Refine hitslop

* Add count to anchor

* Reduce space in compact mode

---------

Co-authored-by: Samuel Newman <mozzius@protonmail.com>
Diffstat (limited to 'src/components/PostControls/util.ts')
-rw-r--r--src/components/PostControls/util.ts24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/components/PostControls/util.ts b/src/components/PostControls/util.ts
new file mode 100644
index 000000000..5d3ea74e4
--- /dev/null
+++ b/src/components/PostControls/util.ts
@@ -0,0 +1,24 @@
+import {type I18n} from '@lingui/core'
+
+/**
+ * This matches `formatCount` from `view/com/util/numeric/format.ts`, but has
+ * additional truncation logic for large numbers. `roundingMode` should always
+ * match the original impl, regardless of if we add more formatting here.
+ */
+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',
+  })
+}