Skip to content

Colota - Android GPS Location tracker

fix(settings): abbreviate stat counts that overflow their column (#577)

Max Dietriche7920e129750
diff --git a/apps/mobile/src/components/features/settings/StatsCard.tsx b/apps/mobile/src/components/features/settings/StatsCard.tsx
index 10104dbf..8c70c4c3 100644
--- a/apps/mobile/src/components/features/settings/StatsCard.tsx
+++ b/apps/mobile/src/components/features/settings/StatsCard.tsx
@@ -8,6 +8,7 @@ import { AlertTriangle, ChevronRight } from "lucide-react-native"
import { useTracking } from "../../../contexts/TrackingProvider"
import { useTheme } from "../../../hooks/useTheme"
import { getQueueColor } from "../../../utils/queueStatus"
+import { formatCount } from "../../../utils/format"
import { fonts } from "../../../styles/typography"
import { HIGH_QUEUE_THRESHOLD, CRITICAL_QUEUE_THRESHOLD } from "../../../constants"
@@ -88,7 +89,9 @@ export function StatsCard({ queueCount, sentCount, todayCount, interval, onManag
{/* Today */}
<View style={styles.statItem}>
<Text style={[styles.statLabel, { color: colors.textSecondary }]}>Today</Text>
- <Text style={[styles.statValue, { color: colors.info }]}>{(todayCount ?? 0).toLocaleString()}</Text>
+ <Text numberOfLines={1} style={[styles.statValue, { color: colors.info }]}>
+ {formatCount(todayCount ?? 0)}
+ </Text>
</View>
<View style={[styles.divider, { backgroundColor: colors.border }]} />
@@ -98,7 +101,9 @@ export function StatsCard({ queueCount, sentCount, todayCount, interval, onManag
{/* Queued */}
<View style={styles.statItem}>
<Text style={[styles.statLabel, { color: colors.textSecondary }]}>Queued</Text>
- <Text style={[styles.statValue, { color: queuedColor }]}>{queueCount.toLocaleString()}</Text>
+ <Text numberOfLines={1} style={[styles.statValue, { color: queuedColor }]}>
+ {formatCount(queueCount)}
+ </Text>
</View>
<View style={[styles.divider, { backgroundColor: colors.border }]} />
@@ -106,7 +111,9 @@ export function StatsCard({ queueCount, sentCount, todayCount, interval, onManag
{/* Sent */}
<View style={styles.statItem}>
<Text style={[styles.statLabel, { color: colors.textSecondary }]}>Sent</Text>
- <Text style={[styles.statValue, { color: colors.success }]}>{sentCount.toLocaleString()}</Text>
+ <Text numberOfLines={1} style={[styles.statValue, { color: colors.success }]}>
+ {formatCount(sentCount)}
+ </Text>
</View>
<View style={[styles.divider, { backgroundColor: colors.border }]} />
@@ -116,7 +123,7 @@ export function StatsCard({ queueCount, sentCount, todayCount, interval, onManag
{/* Interval */}
<View style={styles.statItem}>
<Text style={[styles.statLabel, { color: colors.textSecondary }]}>Interval</Text>
- <Text style={[styles.statValue, { color: colors.info }]}>
+ <Text numberOfLines={1} style={[styles.statValue, { color: colors.info }]}>
{interval}
<Text style={[styles.unit, { color: colors.textSecondary }]}>s</Text>
</Text>
diff --git a/apps/mobile/src/components/features/settings/__tests__/StatsCard.test.tsx b/apps/mobile/src/components/features/settings/__tests__/StatsCard.test.tsx
index 813c0fbd..15f3c581 100644
--- a/apps/mobile/src/components/features/settings/__tests__/StatsCard.test.tsx
+++ b/apps/mobile/src/components/features/settings/__tests__/StatsCard.test.tsx
@@ -63,6 +63,13 @@ describe("StatsCard", () => {
expect(getByText("Interval")).toBeTruthy()
})
+ it("abbreviates a multi-million sent count so the fixed-width column stays one line", () => {
+ const { getByText, queryByText } = render(<StatsCard {...baseProps} sentCount={2_000_000} />)
+
+ expect(getByText("2.0M")).toBeTruthy()
+ expect(queryByText("2,000,000")).toBeNull()
+ })
+
it("does not show Today stat", () => {
const { queryByText } = render(<StatsCard {...baseProps} />)
diff --git a/apps/mobile/src/utils/__tests__/format.test.ts b/apps/mobile/src/utils/__tests__/format.test.ts
new file mode 100644
index 00000000..272150ed
--- /dev/null
+++ b/apps/mobile/src/utils/__tests__/format.test.ts
@@ -0,0 +1,29 @@
+import { formatCount } from "../format"
+
+describe("formatCount", () => {
+ it("keeps counts that fit a stat column exact to the digit", () => {
+ expect(formatCount(0)).toBe("0")
+ // Digits only: the grouping separator is the device locale's, not the assertion's.
+ expect(formatCount(1234).replace(/\D/g, "")).toBe("1234")
+ expect(formatCount(99_999).replace(/\D/g, "")).toBe("99999")
+ })
+
+ it("does not abbreviate below the column's width limit", () => {
+ expect(formatCount(99_999)).not.toMatch(/[KM]$/)
+ })
+
+ it("abbreviates once the grouped digits would overflow the column", () => {
+ expect(formatCount(100_000)).toBe("100K")
+ expect(formatCount(123_456)).toBe("123K")
+ })
+
+ it("floors thousands so nothing below a million reads as 1000K", () => {
+ expect(formatCount(999_999)).toBe("999K")
+ })
+
+ it("switches to millions so a full database stays a few glyphs wide", () => {
+ expect(formatCount(1_000_000)).toBe("1.0M")
+ expect(formatCount(2_000_000)).toBe("2.0M")
+ expect(formatCount(12_345_678)).toBe("12.3M")
+ })
+})
diff --git a/apps/mobile/src/utils/format.ts b/apps/mobile/src/utils/format.ts
index 4b45c980..27a7de21 100644
--- a/apps/mobile/src/utils/format.ts
+++ b/apps/mobile/src/utils/format.ts
@@ -10,6 +10,16 @@ export const formatBytes = (bytes: number): string => {
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`
}
+/**
+ * Formats a point count for the fixed-width stat columns, which fit about six glyphs
+ * at their 24px value size. Abbreviates above that (123456 -> "123K", 2000000 -> "2.0M").
+ */
+export const formatCount = (count: number): string => {
+ if (count < 100_000) return count.toLocaleString()
+ if (count < 1_000_000) return `${Math.floor(count / 1_000)}K`
+ return `${(count / 1_000_000).toFixed(1)}M`
+}
+
/** Clamps `value` to the inclusive range [min, max]. */
export const clamp = (value: number, min: number, max: number): number => Math.max(min, Math.min(max, value))
diff --git a/fastlane/metadata/android/en-US/changelogs/45.txt b/fastlane/metadata/android/en-US/changelogs/45.txt
new file mode 100644
index 00000000..740be132
--- /dev/null
+++ b/fastlane/metadata/android/en-US/changelogs/45.txt
@@ -0,0 +1 @@
+- Large point counts stay on one line in the settings summary, shown as 123K or 2.0M