mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-22 15:11:13 -05:00
Fix display conversion logic
This commit is contained in:
@@ -2,7 +2,7 @@ import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
import { RideTechnicalSpec } from "@/types/database";
|
||||
import { Wrench } from "lucide-react";
|
||||
import { useUnitPreferences } from "@/hooks/useUnitPreferences";
|
||||
import { convertValueFromMetric, detectUnitType, getMetricUnit } from "@/lib/units";
|
||||
import { convertValueFromMetric, detectUnitType, getMetricUnit, getDisplayUnit } from "@/lib/units";
|
||||
|
||||
interface TechnicalSpecificationsProps {
|
||||
specifications?: RideTechnicalSpec[];
|
||||
@@ -26,24 +26,24 @@ export const TechnicalSpecifications = ({ specifications }: TechnicalSpecificati
|
||||
return `${spec.spec_value} ${spec.unit}`;
|
||||
}
|
||||
|
||||
const metricUnit = getMetricUnit(spec.unit);
|
||||
const numericValue = parseFloat(spec.spec_value);
|
||||
|
||||
if (isNaN(numericValue)) {
|
||||
return spec.spec_value;
|
||||
}
|
||||
|
||||
// spec.unit is the metric unit stored in DB (e.g., "km/h")
|
||||
// Get the target display unit based on user preference (e.g., "mph" for imperial)
|
||||
const displayUnit = getDisplayUnit(spec.unit, preferences.measurement_system);
|
||||
|
||||
// Convert from metric (spec.unit) to display unit
|
||||
const convertedValue = convertValueFromMetric(
|
||||
numericValue,
|
||||
spec.unit,
|
||||
metricUnit
|
||||
displayUnit, // Target unit (mph, ft, in)
|
||||
spec.unit // Source metric unit (km/h, m, cm)
|
||||
);
|
||||
|
||||
const targetUnit = preferences.measurement_system === 'metric'
|
||||
? metricUnit
|
||||
: spec.unit;
|
||||
|
||||
return `${convertedValue.toLocaleString()} ${targetUnit}`;
|
||||
return `${convertedValue.toLocaleString()} ${displayUnit}`;
|
||||
};
|
||||
|
||||
// Group specs by category
|
||||
|
||||
Reference in New Issue
Block a user