@@ -10,8 +10,12 @@ import {
1010 cursorUsageWindowDetails ,
1111 displayLimitWindows ,
1212 formatResetsIn ,
13- paceRemainingPercent ,
14- remainingPercent ,
13+ meterPercent ,
14+ paceMarkLabel ,
15+ paceMarkPercent ,
16+ poolMeterPercent ,
17+ refillDelta ,
18+ refillSpan ,
1519 type LimitAccount ,
1620 type LimitPoolWindow ,
1721} from "@t3tools/shared/usageLimits" ;
@@ -26,6 +30,7 @@ import { AppText as Text } from "../../components/ui/AppText";
2630import { ProviderIcon } from "../../components/ProviderIcon" ;
2731import { SettingsScreen } from "../settings/components/SettingsScreen" ;
2832import { environmentPresentations } from "../../state/presentation" ;
33+ import { useAppearancePreferences } from "../settings/appearance/AppearancePreferencesProvider" ;
2934import { ResetCredits } from "./UsageLimitsSection" ;
3035import { usageProviderKind , useProviderColors } from "./usageProviders" ;
3136
@@ -73,17 +78,15 @@ function AccountChip({ email }: { readonly email: string }) {
7378
7479// Same gap-and-tick as the Limits rows: two clipped copies of the segment leave a see-through gap.
7580function PaceGap ( {
76- timeLeft ,
81+ mark ,
7782 children,
7883} : {
79- readonly timeLeft : number | null ;
84+ readonly mark : number | null ;
8085 readonly children : ReactNode ;
8186} ) {
8287 const [ width , setWidth ] = useState ( 0 ) ;
8388 const tickX =
84- timeLeft === null || width < 6
85- ? null
86- : Math . min ( Math . max ( ( width * timeLeft ) / 100 , 3 ) , width - 3 ) ;
89+ mark === null || width < 6 ? null : Math . min ( Math . max ( ( width * mark ) / 100 , 3 ) , width - 3 ) ;
8790 return (
8891 < View
8992 pointerEvents = "none"
@@ -119,13 +122,13 @@ function PaceGap({
119122}
120123
121124function AccountSegment ( {
122- remaining ,
125+ percent ,
123126 color,
124- refillPercent ,
127+ refill ,
125128} : {
126- readonly remaining : number ;
129+ readonly percent : number ;
127130 readonly color : string ;
128- readonly refillPercent : number ;
131+ readonly refill : ReturnType < typeof refillSpan > ;
129132} ) {
130133 const patternId = useId ( ) . replace ( / : / g, "" ) ;
131134 const [ size , setSize ] = useState ( { width : 0 , height : 0 } ) ;
@@ -148,15 +151,15 @@ function AccountSegment({
148151 < Path d = "M-1 1L1 -1M0 6L6 0M5 7L7 5" stroke = { color } strokeWidth = { 1 } opacity = { 0.22 } />
149152 </ Pattern >
150153 </ Defs >
151- { refillPercent > 0 ? (
154+ < Rect width = { `${ percent } %` } height = "100%" fill = { color } opacity = { 0.35 } />
155+ { refill ? (
152156 < Rect
153- x = { `${ 100 - Math . min ( 100 - remaining , refillPercent ) } %` }
154- width = { `${ Math . min ( 100 - remaining , refillPercent ) } %` }
157+ x = { `${ refill . start } %` }
158+ width = { `${ refill . width } %` }
155159 height = "100%"
156160 fill = { `url(#${ patternId } )` }
157161 />
158162 ) : null }
159- < Rect width = { `${ remaining } %` } height = "100%" fill = { color } opacity = { 0.35 } />
160163 </ Svg >
161164 ) : null }
162165 </ View >
@@ -181,6 +184,7 @@ function PoolWindowCard({
181184 readonly wide : boolean ;
182185} ) {
183186 const navigation = useNavigation ( ) ;
187+ const { usageDisplay } = useAppearancePreferences ( ) ;
184188 const [ barWidth , setBarWidth ] = useState ( 0 ) ;
185189 // Each segment needs room for its account, percent and reset to label itself.
186190 const segmentWidth = barWidth / Math . max ( pool . columns . length , 1 ) ;
@@ -203,9 +207,9 @@ function PoolWindowCard({
203207 < Text className = "text-sm font-t3-medium text-foreground" > { label ?? pool . label } </ Text >
204208 < View className = "flex-row items-baseline gap-1.5" >
205209 < Text className = "text-3xl font-t3-bold tabular-nums text-foreground" >
206- { pool . remainingPercent } %
210+ { poolMeterPercent ( pool , usageDisplay ) } %
207211 </ Text >
208- < Text className = "text-sm text-foreground-muted" > left </ Text >
212+ < Text className = "text-sm text-foreground-muted" > { usageDisplay } </ Text >
209213 </ View >
210214 </ View >
211215 { pool . pace ? (
@@ -215,7 +219,7 @@ function PoolWindowCard({
215219 { description ? < Text className = "text-xs text-foreground-muted" > { description } </ Text > : null }
216220 { nextRefill ? (
217221 < Text className = "text-xs tabular-nums text-foreground-muted" >
218- ↻ + { nextRefill . restoresPercent } % { " " }
222+ ↻ { refillDelta ( nextRefill . restoresPercent , usageDisplay ) } { " " }
219223 { formatResetsIn ( nextRefill . member . window , now )
220224 ?. replace ( "resets in " , "in " )
221225 . replace ( "resets now" , "now" ) }
@@ -237,25 +241,30 @@ function PoolWindowCard({
237241 />
238242 ) ;
239243 const { account, window } = member ;
240- const timeLeft = paceRemainingPercent ( window , now ) ;
244+ const percent = meterPercent ( window . usedPercent , usageDisplay ) ;
245+ const mark = paceMarkPercent ( window , now , usageDisplay ) ;
241246 const credits = account . limits . resetCredits ?. availableCount ?? 0 ;
242247 const resetsIn = formatResetsIn ( window , now ) ?. replace ( "resets in " , "" ) ;
243248 return (
244249 < Pressable
245250 key = { account . key }
246251 accessibilityRole = "button"
247- accessibilityLabel = { `Segment ${ index + 1 } , ${ accountName ( account ) } , ${ remainingPercent ( window ) } % left ${ timeLeft === null ? "" : `, ${ timeLeft } % of the window left ` } ` }
252+ accessibilityLabel = { `Segment ${ index + 1 } , ${ accountName ( account ) } , ${ percent } % ${ usageDisplay } ${ mark === null ? "" : `, ${ paceMarkLabel ( mark , usageDisplay ) } ` } ` }
248253 accessibilityHint = "Show account details"
249254 onPress = { ( ) => openAccount ( account ) }
250255 className = { wide ? "h-9 min-w-0 flex-1 rounded-md" : "h-7 min-w-0 flex-1 rounded-md" }
251256 >
252- < PaceGap timeLeft = { timeLeft } >
257+ < PaceGap mark = { mark } >
253258 < View className = "absolute inset-0 rounded-md bg-subtle" />
254259 < View className = "absolute inset-0 overflow-hidden rounded-md" >
255260 < AccountSegment
256- remaining = { remainingPercent ( window ) }
261+ percent = { percent }
257262 color = { normalizeProviderAccentColor ( account . accentColor ) ?? color }
258- refillPercent = { window . resetsAt ? member . refillPercent : 0 }
263+ refill = {
264+ window . resetsAt
265+ ? refillSpan ( window . usedPercent , member . refillPercent , usageDisplay )
266+ : null
267+ }
259268 />
260269 </ View >
261270 </ PaceGap >
@@ -275,7 +284,7 @@ function PoolWindowCard({
275284 </ Text >
276285 ) }
277286 < Text className = "text-sm font-t3-bold tabular-nums text-foreground" >
278- { remainingPercent ( window ) } %
287+ { percent } %
279288 </ Text >
280289 </ View >
281290 { inlineReset && ( resetsIn || credits ) ? (
@@ -328,11 +337,12 @@ function PoolWindowCard({
328337 const segmentColor = normalizeProviderAccentColor ( account . accentColor ) ?? color ;
329338 const credits = account . limits . resetCredits ?. availableCount ?? 0 ;
330339 const resetsIn = formatResetsIn ( window , now ) ;
340+ const percent = meterPercent ( window . usedPercent , usageDisplay ) ;
331341 return (
332342 < Pressable
333343 key = { account . key }
334344 accessibilityRole = "button"
335- accessibilityLabel = { `Segment ${ index + 1 } , ${ accountName ( account ) } , ${ remainingPercent ( window ) } % left ${ resetsIn ? `, ${ resetsIn } ` : "" } ${ credits ? `, ${ credits } reset credits banked` : "" } ` }
345+ accessibilityLabel = { `Segment ${ index + 1 } , ${ accountName ( account ) } , ${ percent } % ${ usageDisplay } ${ resetsIn ? `, ${ resetsIn } ` : "" } ${ credits ? `, ${ credits } reset credits banked` : "" } ` }
336346 accessibilityHint = "Show account details"
337347 onPress = { ( ) => openAccount ( account ) }
338348 className = "min-h-[44px] flex-row items-center gap-2 active:opacity-60"
@@ -353,9 +363,7 @@ function PoolWindowCard({
353363 >
354364 { accountName ( account ) }
355365 </ Text >
356- < Text className = "text-sm font-t3-medium tabular-nums text-foreground" >
357- { remainingPercent ( window ) } %
358- </ Text >
366+ < Text className = "text-sm font-t3-medium tabular-nums text-foreground" > { percent } %</ Text >
359367 < View className = "flex-row items-center gap-1" >
360368 { resetsIn ? (
361369 < >
@@ -539,7 +547,8 @@ export function UsageLimitAccountScreen({ route }: AccountScreenProps) {
539547 . find ( ( candidate ) => candidate . driver === account ?. driver )
540548 ?. windows . find ( ( candidate ) => candidate . id === windowId && candidate . kind === windowKind ) ;
541549 const window = pool ?. members . find ( ( member ) => member . account . key === accountKey ) ?. window ;
542- const evenPace = window ? paceRemainingPercent ( window , now ) : null ;
550+ const { usageDisplay } = useAppearancePreferences ( ) ;
551+ const evenPace = window ? paceMarkPercent ( window , now , usageDisplay ) : null ;
543552 const reset = pool ?. resets . find ( ( candidate ) => candidate . member . account . key === accountKey ) ;
544553 const [ revealed , setRevealed ] = useState ( false ) ;
545554 return (
@@ -583,7 +592,7 @@ export function UsageLimitAccountScreen({ route }: AccountScreenProps) {
583592 < View className = "gap-3 rounded-[24px] border-continuous bg-grouped-card p-4" >
584593 < Text className = "text-sm font-t3-medium text-foreground" > { window . label } </ Text >
585594 < Text className = "text-3xl font-t3-bold tabular-nums text-foreground" >
586- { remainingPercent ( window ) } % left
595+ { meterPercent ( window . usedPercent , usageDisplay ) } % { usageDisplay }
587596 </ Text >
588597 { window . resetsAt ? (
589598 < Text selectable className = "text-sm text-foreground-muted" >
@@ -596,12 +605,13 @@ export function UsageLimitAccountScreen({ route }: AccountScreenProps) {
596605 ) : null }
597606 { evenPace !== null ? (
598607 < Text className = "text-sm text-foreground-muted" >
599- Even pace: { evenPace } % left by now
608+ Even pace: { evenPace } % { usageDisplay } by now
600609 </ Text >
601610 ) : null }
602611 { reset && reset . restoresPercent > 0 ? (
603612 < Text className = "text-sm text-foreground-muted" >
604- Restores { reset . restoresPercent } % of the pool
613+ { usageDisplay === "used" ? "Clears" : "Restores" } { reset . restoresPercent } % of the
614+ pool
605615 </ Text >
606616 ) : null }
607617 </ View >
0 commit comments