11import { useMemo } from 'react' ;
22import { useSessionBarSnapshot } from '@irdashies/context' ;
33
4+ type TemperatureUnit = 'Metric' | 'Imperial' ;
5+
46interface UseTrackTemperatureOptions {
5- airTempUnit ?: 'Metric' | 'Imperial' ;
6- trackTempUnit ?: 'Metric' | 'Imperial' ;
7+ airTempUnit ?: TemperatureUnit ;
8+ trackTempUnit ?: TemperatureUnit ;
79}
810
911export const useTrackTemperature = (
@@ -15,24 +17,22 @@ export const useTrackTemperature = (
1517 const airTempVal = snapshot ?. airTemp ;
1618
1719 const trackTemp = useMemo ( ( ) => {
18- const trackTemp = trackTempVal ?? 0 ;
19- if ( trackTemp === null || trackTemp === undefined ) return '' ;
20+ if ( trackTempVal === undefined ) return '' ;
2021
2122 // Convert to Fahrenheit if Imperial unit is selected
2223 const displayTemp =
23- trackTempUnit === 'Imperial' ? ( trackTemp * 9 ) / 5 + 32 : trackTemp ;
24+ trackTempUnit === 'Imperial' ? ( trackTempVal * 9 ) / 5 + 32 : trackTempVal ;
2425
2526 const unit = trackTempUnit === 'Imperial' ? 'F' : 'C' ;
2627 return `${ displayTemp . toFixed ( 0 ) } °${ unit } ` ;
2728 } , [ trackTempVal , trackTempUnit ] ) ;
2829
2930 const airTemp = useMemo ( ( ) => {
30- const airTemp = airTempVal ?? 0 ;
31- if ( airTemp === null || airTemp === undefined ) return '' ;
31+ if ( airTempVal === undefined ) return '' ;
3232
3333 // Convert to Fahrenheit if Imperial unit is selected
3434 const displayTemp =
35- airTempUnit === 'Imperial' ? ( airTemp * 9 ) / 5 + 32 : airTemp ;
35+ airTempUnit === 'Imperial' ? ( airTempVal * 9 ) / 5 + 32 : airTempVal ;
3636
3737 const unit = airTempUnit === 'Imperial' ? 'F' : 'C' ;
3838 return `${ displayTemp . toFixed ( 0 ) } °${ unit } ` ;
0 commit comments