Fix unit display errors

This commit is contained in:
gpt-engineer-app[bot]
2025-09-28 22:51:44 +00:00
parent 8f13796567
commit a6e9d77bda
5 changed files with 114 additions and 4 deletions

View File

@@ -47,7 +47,7 @@ export function MeasurementDisplay({
return defaultPrefs;
}, [profile]);
const { displayValue, unit, alternateDisplay } = useMemo(() => {
const { displayValue, unit, alternateDisplay, tooltipText } = useMemo(() => {
const system = unitPreferences.measurement_system;
let displayValue: number;
@@ -88,12 +88,13 @@ export function MeasurementDisplay({
}
const alternateDisplay = showBothUnits ? ` (${alternateValue} ${alternateUnit})` : '';
const tooltipText = showBothUnits ? undefined : `${alternateValue} ${alternateUnit}`;
return { displayValue, unit, alternateDisplay };
return { displayValue, unit, alternateDisplay, tooltipText };
}, [value, type, unitPreferences.measurement_system, showBothUnits]);
return (
<span className={className} title={showBothUnits ? undefined : alternateDisplay ? `${alternateValue} ${alternateUnit}` : undefined}>
<span className={className} title={tooltipText}>
{displayValue} {unit}{alternateDisplay}
</span>
);

View File

@@ -0,0 +1,52 @@
import { MeasurementDisplay } from './measurement-display';
interface SpeedDisplayProps {
kmh: number;
showBothUnits?: boolean;
className?: string;
}
export function SpeedDisplay({ kmh, showBothUnits = false, className }: SpeedDisplayProps) {
return (
<MeasurementDisplay
value={kmh}
type="speed"
showBothUnits={showBothUnits}
className={className}
/>
);
}
interface DistanceDisplayProps {
meters: number;
showBothUnits?: boolean;
className?: string;
}
export function DistanceDisplay({ meters, showBothUnits = false, className }: DistanceDisplayProps) {
return (
<MeasurementDisplay
value={meters}
type="distance"
showBothUnits={showBothUnits}
className={className}
/>
);
}
interface HeightDisplayProps {
cm: number;
showBothUnits?: boolean;
className?: string;
}
export function HeightDisplay({ cm, showBothUnits = false, className }: HeightDisplayProps) {
return (
<MeasurementDisplay
value={cm}
type="height"
showBothUnits={showBothUnits}
className={className}
/>
);
}