@@ -27,7 +27,7 @@ import {
2727 formatUsd ,
2828 makeWindow ,
2929} from "@t3tools/shared/usageFormat" ;
30- import { useCallback , useLayoutEffect , useMemo , useRef , useState , type ReactNode } from "react" ;
30+ import { useLayoutEffect , useRef , useState , type ReactNode } from "react" ;
3131import { Platform , Pressable , RefreshControl , View } from "react-native" ;
3232import Animated , {
3333 FadeIn ,
@@ -135,29 +135,19 @@ export function UsageRouteScreen() {
135135 ( environment ) => environment . canReadDiagnostics ,
136136 ) ;
137137
138- const days = useMemo (
139- ( ) => enumerateDays ( window . sinceDay , window . untilDay ) ,
140- [ window . sinceDay , window . untilDay ] ,
141- ) ;
142- const chartDays = useMemo (
143- ( ) =>
144- isPast24Hours && window . sinceTime !== undefined && window . untilTime !== undefined
145- ? enumerateHourStarts ( window . sinceTime , window . untilTime )
146- : days ,
147- [ days , isPast24Hours , window . sinceTime , window . untilTime ] ,
148- ) ;
149- const chartTotals = useMemo (
150- ( ) : readonly DailyTotals [ ] =>
151- isPast24Hours
152- ? merged . hourly . map ( ( hour ) => ( {
153- day : hour . hourStart ,
154- costUsd : hour . costUsd ,
155- totalTokens : hour . totalTokens ,
156- byProvider : hour . byProvider ,
157- } ) )
158- : merged . daily ,
159- [ isPast24Hours , merged . daily , merged . hourly ] ,
160- ) ;
138+ const days = enumerateDays ( window . sinceDay , window . untilDay ) ;
139+ const chartDays =
140+ isPast24Hours && window . sinceTime !== undefined && window . untilTime !== undefined
141+ ? enumerateHourStarts ( window . sinceTime , window . untilTime )
142+ : days ;
143+ const chartTotals : readonly DailyTotals [ ] = isPast24Hours
144+ ? merged . hourly . map ( ( hour ) => ( {
145+ day : hour . hourStart ,
146+ costUsd : hour . costUsd ,
147+ totalTokens : hour . totalTokens ,
148+ byProvider : hour . byProvider ,
149+ } ) )
150+ : merged . daily ;
161151
162152 const [ refreshingUsage , setRefreshingUsage ] = useState ( false ) ;
163153 const refreshingRef = useRef ( false ) ;
@@ -196,62 +186,52 @@ export function UsageRouteScreen() {
196186 selectedEnvironmentIds === null
197187 ? "line.3.horizontal.decrease"
198188 : "line.3.horizontal.decrease.circle.fill" ;
199- const environmentActions = useMemo (
200- ( ) => [
201- {
202- id : "all" ,
203- title : "All environments" ,
204- subtitle : undefined ,
205- state : selectedEnvironmentIds === null ? ( "on" as const ) : ( "off" as const ) ,
206- } ,
207- ...environments . map ( ( environment ) => ( {
208- id : environment . environmentId ,
209- title : environment . label ,
210- subtitle : usageEnvironmentStatus ( environment , refreshingUsage ) ,
211- state :
212- selectedEnvironmentIds === null || selectedEnvironmentIds . has ( environment . environmentId )
213- ? ( "on" as const )
214- : ( "off" as const ) ,
215- } ) ) ,
216- ] ,
217- [ environments , refreshingUsage , selectedEnvironmentIds ] ,
218- ) ;
219- const selectEnvironment = useCallback (
220- ( value : string ) => {
221- if ( value === "all" ) {
222- setSelectedEnvironmentIds ( null ) ;
223- return ;
224- }
225- const id = EnvironmentId . make ( value ) ;
226- setSelectedEnvironmentIds ( ( selected ) => toggleUsageEnvironment ( selected , environments , id ) ) ;
189+ const environmentActions = [
190+ {
191+ id : "all" ,
192+ title : "All environments" ,
193+ subtitle : undefined ,
194+ state : selectedEnvironmentIds === null ? ( "on" as const ) : ( "off" as const ) ,
227195 } ,
228- [ environments ] ,
229- ) ;
230- const environmentFilter = useMemo (
231- ( ) =>
232- showEnvironmentFilter ? (
233- < Menu
234- accessible
235- accessibilityRole = "button"
236- accessibilityLabel = "Filter usage environments"
237- title = "Environments"
238- actions = { environmentActions }
239- onPressAction = { ( { nativeEvent } ) => selectEnvironment ( nativeEvent . event ) }
240- >
241- < Pressable
242- accessibilityRole = "button"
243- accessibilityLabel = "Filter usage environments"
244- className = { cn (
245- "items-center justify-center rounded-full" ,
246- Platform . OS === "ios" ? "size-[28px]" : "size-[44px]" ,
247- ) }
248- >
249- < SymbolView name = { filterIcon } size = { 22 } tintColorClassName = "accent-icon" />
250- </ Pressable >
251- </ Menu >
252- ) : null ,
253- [ showEnvironmentFilter , environmentActions , selectEnvironment , filterIcon ] ,
254- ) ;
196+ ...environments . map ( ( environment ) => ( {
197+ id : environment . environmentId ,
198+ title : environment . label ,
199+ subtitle : usageEnvironmentStatus ( environment , refreshingUsage ) ,
200+ state :
201+ selectedEnvironmentIds === null || selectedEnvironmentIds . has ( environment . environmentId )
202+ ? ( "on" as const )
203+ : ( "off" as const ) ,
204+ } ) ) ,
205+ ] ;
206+ const selectEnvironment = ( value : string ) => {
207+ if ( value === "all" ) {
208+ setSelectedEnvironmentIds ( null ) ;
209+ return ;
210+ }
211+ const id = EnvironmentId . make ( value ) ;
212+ setSelectedEnvironmentIds ( ( selected ) => toggleUsageEnvironment ( selected , environments , id ) ) ;
213+ } ;
214+ const environmentFilter = showEnvironmentFilter ? (
215+ < Menu
216+ accessible
217+ accessibilityRole = "button"
218+ accessibilityLabel = "Filter usage environments"
219+ title = "Environments"
220+ actions = { environmentActions }
221+ onPressAction = { ( { nativeEvent } ) => selectEnvironment ( nativeEvent . event ) }
222+ >
223+ < Pressable
224+ accessibilityRole = "button"
225+ accessibilityLabel = "Filter usage environments"
226+ className = { cn (
227+ "items-center justify-center rounded-full" ,
228+ Platform . OS === "ios" ? "size-[28px]" : "size-[44px]" ,
229+ ) }
230+ >
231+ < SymbolView name = { filterIcon } size = { 22 } tintColorClassName = "accent-icon" />
232+ </ Pressable >
233+ </ Menu >
234+ ) : null ;
255235
256236 useLayoutEffect ( ( ) => {
257237 if ( Platform . OS === "ios" ) {
@@ -440,15 +420,11 @@ function CursorEnableAction({
440420 const [ pending , setPending ] = useState ( false ) ;
441421 const enable = async ( ) => {
442422 setPending ( true ) ;
443- try {
444- const result = await updateSettings ( {
445- environmentId,
446- input : { patch : { cursorKeychainUsageEnabled : true } } ,
447- } ) ;
448- if ( result . _tag === "Success" ) onEnabled ( ) ;
449- } finally {
450- setPending ( false ) ;
451- }
423+ const result = await updateSettings ( {
424+ environmentId,
425+ input : { patch : { cursorKeychainUsageEnabled : true } } ,
426+ } ) . finally ( ( ) => setPending ( false ) ) ;
427+ if ( result . _tag === "Success" ) onEnabled ( ) ;
452428 } ;
453429 return (
454430 < Pressable
0 commit comments