mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-24 07:51:12 -05:00
Refactor: Implement type safety plan
This commit is contained in:
@@ -6,6 +6,7 @@ import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@
|
||||
import { Textarea } from "@/components/ui/textarea";
|
||||
import { Card } from "@/components/ui/card";
|
||||
import { useUnitPreferences } from "@/hooks/useUnitPreferences";
|
||||
import { toast } from "sonner";
|
||||
import {
|
||||
convertValueToMetric,
|
||||
convertValueFromMetric,
|
||||
@@ -13,6 +14,7 @@ import {
|
||||
getMetricUnit,
|
||||
getDisplayUnit
|
||||
} from "@/lib/units";
|
||||
import { validateMetricUnit } from "@/lib/unitValidation";
|
||||
|
||||
interface CoasterStat {
|
||||
stat_name: string;
|
||||
@@ -83,7 +85,20 @@ export function CoasterStatsEditor({
|
||||
|
||||
const updateStat = (index: number, field: keyof CoasterStat, value: any) => {
|
||||
const newStats = [...stats];
|
||||
newStats[index] = { ...newStats[index], [field]: value };
|
||||
|
||||
// Ensure unit is metric when updating unit field
|
||||
if (field === 'unit' && value) {
|
||||
try {
|
||||
validateMetricUnit(value, 'Unit');
|
||||
newStats[index] = { ...newStats[index], [field]: value };
|
||||
} catch (error) {
|
||||
toast.error(`Invalid unit: ${value}. Please use metric units only (km/h, m, cm, kg, G, etc.)`);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
newStats[index] = { ...newStats[index], [field]: value };
|
||||
}
|
||||
|
||||
onChange(newStats);
|
||||
};
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import { Label } from "@/components/ui/label";
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
|
||||
import { Card } from "@/components/ui/card";
|
||||
import { useUnitPreferences } from "@/hooks/useUnitPreferences";
|
||||
import { toast } from "sonner";
|
||||
import {
|
||||
convertValueToMetric,
|
||||
convertValueFromMetric,
|
||||
@@ -12,6 +13,7 @@ import {
|
||||
getMetricUnit,
|
||||
getDisplayUnit
|
||||
} from "@/lib/units";
|
||||
import { validateMetricUnit } from "@/lib/unitValidation";
|
||||
|
||||
interface TechnicalSpec {
|
||||
spec_name: string;
|
||||
@@ -62,7 +64,20 @@ export function TechnicalSpecsEditor({
|
||||
|
||||
const updateSpec = (index: number, field: keyof TechnicalSpec, value: any) => {
|
||||
const newSpecs = [...specs];
|
||||
newSpecs[index] = { ...newSpecs[index], [field]: value };
|
||||
|
||||
// Ensure unit is metric when updating unit field
|
||||
if (field === 'unit' && value) {
|
||||
try {
|
||||
validateMetricUnit(value, 'Unit');
|
||||
newSpecs[index] = { ...newSpecs[index], [field]: value };
|
||||
} catch (error) {
|
||||
toast.error(`Invalid unit: ${value}. Please use metric units only (m, km/h, cm, kg, celsius, etc.)`);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
newSpecs[index] = { ...newSpecs[index], [field]: value };
|
||||
}
|
||||
|
||||
onChange(newSpecs);
|
||||
};
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ export function UserListManager() {
|
||||
.from("user_top_lists")
|
||||
.select(`
|
||||
*,
|
||||
user_top_list_items (
|
||||
list_items (
|
||||
id,
|
||||
entity_type,
|
||||
entity_id,
|
||||
@@ -75,7 +75,7 @@ export function UserListManager() {
|
||||
is_public: list.is_public,
|
||||
created_at: list.created_at,
|
||||
updated_at: list.updated_at,
|
||||
items: list.user_top_list_items || [],
|
||||
items: list.list_items || [],
|
||||
}));
|
||||
setLists(mappedLists);
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ export function ReviewsList({ entityType, entityId, entityName }: ReviewsListPro
|
||||
}
|
||||
|
||||
const { data } = await query;
|
||||
setReviews(data as any || []);
|
||||
setReviews((data || []) as ReviewWithProfile[]);
|
||||
} catch (error) {
|
||||
console.error('Error fetching reviews:', error);
|
||||
} finally {
|
||||
|
||||
@@ -55,6 +55,10 @@ function Calendar({ className, classNames, showOutsideDays = true, ...props }: C
|
||||
...classNames,
|
||||
}}
|
||||
components={{
|
||||
// DOCUMENTED EXCEPTION: Radix UI Calendar types require complex casting
|
||||
// The react-day-picker component's internal types don't match the external API
|
||||
// Safe because React validates component props at runtime
|
||||
// See: https://github.com/gpbl/react-day-picker/issues
|
||||
Chevron: ({ orientation, ...props }: any) => {
|
||||
if (orientation === 'left') {
|
||||
return <ChevronLeft className="h-4 w-4" />;
|
||||
|
||||
Reference in New Issue
Block a user