From a3e58c648b8d03de98f7340ebdfdd6f9f5c3a261 Mon Sep 17 00:00:00 2001 From: Theo Browne Date: Sat, 8 Aug 2026 15:33:24 -0700 Subject: [PATCH] fix(web): unambiguous limits copy Every percentage now reads 'N% used' in both the hover card and the page strip. Drop plan text, the hover footer, and the freshness caption unless the snapshot is actually stale (>15m). 24h times, m/d dates. Co-Authored-By: Claude Fable 5 --- .../src/components/usage/AccountLimits.tsx | 75 ++++++------------- apps/web/src/usage/limitsFormat.ts | 19 +++-- 2 files changed, 37 insertions(+), 57 deletions(-) diff --git a/apps/web/src/components/usage/AccountLimits.tsx b/apps/web/src/components/usage/AccountLimits.tsx index afd8ea41ff..18475e0767 100644 --- a/apps/web/src/components/usage/AccountLimits.tsx +++ b/apps/web/src/components/usage/AccountLimits.tsx @@ -4,6 +4,10 @@ * window a provider adds or brings back (Codex's paused 5-hour) appears * without a client change. * + * Every percentage is labelled `used` inline - a bare number cannot say + * whether it is used or remaining. Snapshot age only renders once the data + * is actually stale; fresh data needs no caption. + * * @module AccountLimits */ import type { AccountLimitsSnapshot, AccountLimitsWindow } from "@t3tools/contracts"; @@ -14,6 +18,9 @@ import { useAccountLimits } from "../../state/accountLimits"; import { formatAgo, formatResetAt, formatResetIn } from "../../usage/limitsFormat"; import { PROVIDER_COLOR, PROVIDER_LABEL, PROVIDER_MARK, PROVIDER_ORDER } from "./usageProviders"; +/** Age past which a snapshot stops being "current" and earns a caption. */ +const STALE_AFTER_MS = 15 * 60_000; + /** * Reset countdowns and snapshot ages drift as time passes, not as data * changes; a coarse tick keeps them honest without re-fetching. @@ -27,19 +34,6 @@ function useNowMs(intervalMs = 30_000): number { return nowMs; } -const PLAN_LABEL: Record = { - max: "Max", - pro: "Pro", - plus: "Plus", - team: "Team", - enterprise: "Enterprise", -}; - -function formatPlan(plan: string | null): string | null { - if (plan === null) return null; - return PLAN_LABEL[plan] ?? plan.charAt(0).toUpperCase() + plan.slice(1); -} - function usageTone(usedPercent: number): string | undefined { if (usedPercent >= 95) return "text-red-400"; if (usedPercent >= 80) return "text-amber-400"; @@ -60,18 +54,12 @@ function LimitMeter({ window, color }: { window: AccountLimitsWindow; color: str ); } -function SnapshotFreshness({ - snapshot, - nowMs, -}: { - snapshot: AccountLimitsSnapshot; - nowMs: number; -}) { +/** `6h ago`, and only once the snapshot is old enough to matter. */ +function SnapshotAge({ snapshot, nowMs }: { snapshot: AccountLimitsSnapshot; nowMs: number }) { + const ageMs = nowMs - Date.parse(snapshot.asOf); + if (!Number.isFinite(ageMs) || ageMs < STALE_AFTER_MS) return null; return ( - - {snapshot.source === "transcript" ? "last session · " : ""} - {formatAgo(snapshot.asOf, nowMs)} - + {formatAgo(snapshot.asOf, nowMs)} ); } @@ -89,11 +77,10 @@ export function AccountLimitsHoverCard() { } return ( -
+
{PROVIDER_ORDER.map((provider) => { const snapshot = snapshots.get(provider); const Mark = PROVIDER_MARK[provider]; - const plan = formatPlan(snapshot?.plan ?? null); return (
@@ -101,13 +88,8 @@ export function AccountLimitsHoverCard() { {PROVIDER_LABEL[provider]} - {plan !== null ? ( - {plan} - ) : null} - {snapshot !== undefined ? ( - - ) : null} + {snapshot !== undefined ? : null}
{snapshot === undefined || snapshot.windows.length === 0 ? ( @@ -115,19 +97,19 @@ export function AccountLimitsHoverCard() { ) : ( snapshot.windows.map((window) => (
- + {window.label} - {Math.round(window.usedPercent)}% + {Math.round(window.usedPercent)}% used - + {formatResetAt(window.resetsAt, nowMs) ?? ""}
@@ -136,9 +118,6 @@ export function AccountLimitsHoverCard() {
); })} -

- % used · click for details -

); } @@ -159,7 +138,6 @@ export function AccountLimitsSection() { {PROVIDER_ORDER.map((provider) => { const snapshot = snapshots.get(provider); const Mark = PROVIDER_MARK[provider]; - const plan = formatPlan(snapshot?.plan ?? null); return (
@@ -167,20 +145,15 @@ export function AccountLimitsSection() { {PROVIDER_LABEL[provider]} - {plan !== null ? ( - {plan} - ) : null} {snapshot !== undefined ? ( - + ) : null}
{snapshot === undefined || snapshot.windows.length === 0 ? (

- {isPending && snapshot === undefined - ? "Loading…" - : `No limit data yet. Run a ${PROVIDER_LABEL[provider]} session.`} + {isPending && snapshot === undefined ? "Loading…" : "No limit data yet"}

) : ( snapshot.windows.map((window) => { @@ -194,15 +167,15 @@ export function AccountLimitsSection() { - {Math.round(window.usedPercent)}% + {Math.round(window.usedPercent)}% used - + {resetAt === null - ? "no traffic yet" + ? "" : `resets ${resetAt}${resetIn === null ? "" : ` · ${resetIn}`}`}
diff --git a/apps/web/src/usage/limitsFormat.ts b/apps/web/src/usage/limitsFormat.ts index 8a587fedec..21b3f5751c 100644 --- a/apps/web/src/usage/limitsFormat.ts +++ b/apps/web/src/usage/limitsFormat.ts @@ -4,15 +4,21 @@ * @module limitsFormat */ -const TIME = new Intl.DateTimeFormat("en-US", { hour: "numeric", minute: "2-digit" }); -const WEEKDAY_TIME = new Intl.DateTimeFormat("en-US", { - weekday: "short", - hour: "numeric", +const TIME = new Intl.DateTimeFormat("en-US", { + hourCycle: "h23", + hour: "2-digit", + minute: "2-digit", +}); +const DATE_TIME = new Intl.DateTimeFormat("en-US", { + month: "numeric", + day: "numeric", + hourCycle: "h23", + hour: "2-digit", minute: "2-digit", }); /** - * When a window resets: `4:00 PM` inside 24 hours, `Tue 10:00 AM` beyond. + * When a window resets: `16:00` inside 24 hours, `8/12 16:00` beyond. * Null for windows with no reset clock yet, "now" once the moment has passed * (the provider refreshes lazily, so a stale timestamp lingers briefly). */ @@ -21,7 +27,8 @@ export function formatResetAt(resetsAt: string | null, nowMs: number): string | const at = Date.parse(resetsAt); if (Number.isNaN(at)) return null; if (at <= nowMs) return "now"; - return at - nowMs < 24 * 60 * 60 * 1000 ? TIME.format(at) : WEEKDAY_TIME.format(at); + if (at - nowMs < 24 * 60 * 60 * 1000) return TIME.format(at); + return DATE_TIME.format(at).replace(", ", " "); } /** Coarse time-until-reset: `in 45m`, `in 2h`, `in 3d`. */