From f061bb9d5fa322d0b5f9d29b8ba3fcc985d40ba0 Mon Sep 17 00:00:00 2001 From: "gpt-engineer-app[bot]" <159125892+gpt-engineer-app[bot]@users.noreply.github.com> Date: Fri, 3 Oct 2025 13:54:27 +0000 Subject: [PATCH] Refactor: Implement cleanup plan --- src/components/admin/RideForm.tsx | 29 +++++------ src/components/rides/RidePhotoGallery.tsx | 5 -- .../rides/RidePhotoGalleryWrapper.tsx | 22 --------- src/components/ui/measurement-display.tsx | 48 +++++++------------ .../upload/UppyPhotoSubmissionUpload.tsx | 26 ++++------ src/lib/units.ts | 48 +------------------ src/pages/RideDetail.tsx | 15 +++--- src/types/database.ts | 7 +-- src/types/submissions.ts | 4 -- 9 files changed, 49 insertions(+), 155 deletions(-) delete mode 100644 src/components/rides/RidePhotoGallery.tsx delete mode 100644 src/components/rides/RidePhotoGalleryWrapper.tsx diff --git a/src/components/admin/RideForm.tsx b/src/components/admin/RideForm.tsx index 6d90e896..4561c114 100644 --- a/src/components/admin/RideForm.tsx +++ b/src/components/admin/RideForm.tsx @@ -25,12 +25,9 @@ import { TechnicalSpecsEditor } from './editors/TechnicalSpecsEditor'; import { CoasterStatsEditor } from './editors/CoasterStatsEditor'; import { FormerNamesEditor } from './editors/FormerNamesEditor'; import { - convertSpeed, - convertDistance, - convertHeight, - convertSpeedToMetric, - convertDistanceToMetric, - convertHeightToMetric, + convertValueToMetric, + convertValueFromMetric, + getDisplayUnit, getSpeedUnit, getDistanceUnit, getHeightUnit @@ -202,26 +199,26 @@ export function RideForm({ onSubmit, onCancel, initialData, isEditing = false }: closing_date: initialData?.closing_date || '', // Convert metric values to user's preferred unit for display height_requirement: initialData?.height_requirement - ? convertHeight(initialData.height_requirement, measurementSystem) + ? convertValueFromMetric(initialData.height_requirement, getDisplayUnit('cm', measurementSystem), 'cm') : undefined, age_requirement: initialData?.age_requirement || undefined, capacity_per_hour: initialData?.capacity_per_hour || undefined, duration_seconds: initialData?.duration_seconds || undefined, max_speed_kmh: initialData?.max_speed_kmh - ? convertSpeed(initialData.max_speed_kmh, measurementSystem) + ? convertValueFromMetric(initialData.max_speed_kmh, getDisplayUnit('km/h', measurementSystem), 'km/h') : undefined, max_height_meters: initialData?.max_height_meters - ? convertDistance(initialData.max_height_meters, measurementSystem) + ? convertValueFromMetric(initialData.max_height_meters, getDisplayUnit('m', measurementSystem), 'm') : undefined, length_meters: initialData?.length_meters - ? convertDistance(initialData.length_meters, measurementSystem) + ? convertValueFromMetric(initialData.length_meters, getDisplayUnit('m', measurementSystem), 'm') : undefined, inversions: initialData?.inversions || undefined, coaster_type: initialData?.coaster_type || undefined, seating_type: initialData?.seating_type || undefined, intensity_level: initialData?.intensity_level || undefined, drop_height_meters: initialData?.drop_height_meters - ? convertDistance(initialData.drop_height_meters, measurementSystem) + ? convertValueFromMetric(initialData.drop_height_meters, getDisplayUnit('m', measurementSystem), 'm') : undefined, max_g_force: initialData?.max_g_force || undefined, former_names: initialData?.former_names || '', @@ -247,19 +244,19 @@ export function RideForm({ onSubmit, onCancel, initialData, isEditing = false }: ...data, status: dbStatus, height_requirement: data.height_requirement - ? convertHeightToMetric(data.height_requirement, measurementSystem) + ? convertValueToMetric(data.height_requirement, getDisplayUnit('cm', measurementSystem)) : undefined, max_speed_kmh: data.max_speed_kmh - ? convertSpeedToMetric(data.max_speed_kmh, measurementSystem) + ? convertValueToMetric(data.max_speed_kmh, getDisplayUnit('km/h', measurementSystem)) : undefined, max_height_meters: data.max_height_meters - ? convertDistanceToMetric(data.max_height_meters, measurementSystem) + ? convertValueToMetric(data.max_height_meters, getDisplayUnit('m', measurementSystem)) : undefined, length_meters: data.length_meters - ? convertDistanceToMetric(data.length_meters, measurementSystem) + ? convertValueToMetric(data.length_meters, getDisplayUnit('m', measurementSystem)) : undefined, drop_height_meters: data.drop_height_meters - ? convertDistanceToMetric(data.drop_height_meters, measurementSystem) + ? convertValueToMetric(data.drop_height_meters, getDisplayUnit('m', measurementSystem)) : undefined, // ⚠️ Remove JSON stringification - use relational tables instead // These fields are deprecated and should not be set diff --git a/src/components/rides/RidePhotoGallery.tsx b/src/components/rides/RidePhotoGallery.tsx deleted file mode 100644 index 97017038..00000000 --- a/src/components/rides/RidePhotoGallery.tsx +++ /dev/null @@ -1,5 +0,0 @@ -/** - * @deprecated Use EntityPhotoGallery directly or import from RidePhotoGalleryWrapper - * This file is kept for backwards compatibility - */ -export { RidePhotoGallery } from './RidePhotoGalleryWrapper'; \ No newline at end of file diff --git a/src/components/rides/RidePhotoGalleryWrapper.tsx b/src/components/rides/RidePhotoGalleryWrapper.tsx deleted file mode 100644 index 1645061a..00000000 --- a/src/components/rides/RidePhotoGalleryWrapper.tsx +++ /dev/null @@ -1,22 +0,0 @@ -import { EntityPhotoGallery } from '@/components/upload/EntityPhotoGallery'; - -interface RidePhotoGalleryProps { - rideId: string; - rideName: string; - parkId?: string; -} - -/** - * Backwards-compatible wrapper for RidePhotoGallery - * Uses the generic EntityPhotoGallery component internally - */ -export function RidePhotoGallery({ rideId, rideName, parkId }: RidePhotoGalleryProps) { - return ( - - ); -} diff --git a/src/components/ui/measurement-display.tsx b/src/components/ui/measurement-display.tsx index a3f066df..ce3937e6 100644 --- a/src/components/ui/measurement-display.tsx +++ b/src/components/ui/measurement-display.tsx @@ -1,9 +1,8 @@ import { useMemo } from 'react'; import { useUnitPreferences } from '@/hooks/useUnitPreferences'; import { - convertSpeed, - convertDistance, - convertHeight, + convertValueFromMetric, + getDisplayUnit, getSpeedUnit, getDistanceUnit, getHeightUnit, @@ -29,47 +28,36 @@ export function MeasurementDisplay({ const { displayValue, unit, alternateDisplay, tooltipText } = useMemo(() => { const system = unitPreferences.measurement_system; - let displayValue: number; - let unit: string; - let alternateValue: number; - let alternateUnit: string; + let metricUnit: string; + let displayUnit: string; + let alternateSystem: MeasurementSystem; switch (type) { case 'speed': - displayValue = convertSpeed(value, system); - unit = getSpeedUnit(system); - alternateValue = convertSpeed(value, system === 'metric' ? 'imperial' : 'metric'); - alternateUnit = getSpeedUnit(system === 'metric' ? 'imperial' : 'metric'); + metricUnit = 'km/h'; break; case 'distance': - displayValue = convertDistance(value, system); - unit = getDistanceUnit(system); - alternateValue = convertDistance(value, system === 'metric' ? 'imperial' : 'metric'); - alternateUnit = getDistanceUnit(system === 'metric' ? 'imperial' : 'metric'); + case 'short_distance': + metricUnit = 'm'; break; case 'height': - displayValue = convertHeight(value, system); - unit = getHeightUnit(system); - alternateValue = convertHeight(value, system === 'metric' ? 'imperial' : 'metric'); - alternateUnit = getHeightUnit(system === 'metric' ? 'imperial' : 'metric'); - break; - case 'short_distance': - displayValue = convertDistance(value, system); - unit = getShortDistanceUnit(system); - alternateValue = convertDistance(value, system === 'metric' ? 'imperial' : 'metric'); - alternateUnit = getShortDistanceUnit(system === 'metric' ? 'imperial' : 'metric'); + metricUnit = 'cm'; break; default: - displayValue = value; - unit = ''; - alternateValue = value; - alternateUnit = ''; + return { displayValue: value, unit: '', alternateDisplay: '', tooltipText: undefined }; } + alternateSystem = system === 'metric' ? 'imperial' : 'metric'; + displayUnit = getDisplayUnit(metricUnit, system); + const alternateUnit = getDisplayUnit(metricUnit, alternateSystem); + + const displayValue = convertValueFromMetric(value, displayUnit, metricUnit); + const alternateValue = convertValueFromMetric(value, alternateUnit, metricUnit); + const alternateDisplay = showBothUnits ? ` (${alternateValue} ${alternateUnit})` : ''; const tooltipText = showBothUnits ? undefined : `${alternateValue} ${alternateUnit}`; - return { displayValue, unit, alternateDisplay, tooltipText }; + return { displayValue, unit: displayUnit, alternateDisplay, tooltipText }; }, [value, type, unitPreferences.measurement_system, showBothUnits]); return ( diff --git a/src/components/upload/UppyPhotoSubmissionUpload.tsx b/src/components/upload/UppyPhotoSubmissionUpload.tsx index 9759becf..cc6ee112 100644 --- a/src/components/upload/UppyPhotoSubmissionUpload.tsx +++ b/src/components/upload/UppyPhotoSubmissionUpload.tsx @@ -20,14 +20,7 @@ export function UppyPhotoSubmissionUpload({ entityId, entityType, parentId, - // Legacy props (deprecated) - parkId, - rideId, }: UppyPhotoSubmissionUploadProps) { - // Support legacy props - const finalEntityId = entityId || rideId || parkId || ''; - const finalEntityType = entityType || (rideId ? 'ride' : parkId ? 'park' : 'ride'); - const finalParentId = parentId || (rideId ? parkId : undefined); const [title, setTitle] = useState(''); const [photos, setPhotos] = useState([]); const [isSubmitting, setIsSubmitting] = useState(false); @@ -203,9 +196,9 @@ export function UppyPhotoSubmissionUpload({ .from('photo_submissions') .insert({ submission_id: submissionData.id, - entity_type: finalEntityType, - entity_id: finalEntityId, - parent_id: finalParentId || null, + entity_type: entityType, + entity_id: entityId, + parent_id: parentId || null, title: title.trim() || null, }) .select() @@ -239,8 +232,8 @@ export function UppyPhotoSubmissionUpload({ console.log('✅ Photo submission created:', { submission_id: submissionData.id, photo_submission_id: photoSubmissionData.id, - entity_type: finalEntityType, - entity_id: finalEntityId, + entity_type: entityType, + entity_id: entityId, photo_count: photoItems.length, }); @@ -285,12 +278,9 @@ export function UppyPhotoSubmissionUpload({ const metadata = { submissionType: 'photo', - entityId: finalEntityId, - entityType: finalEntityType, - parentId: finalParentId, - // Legacy support - parkId: finalEntityType === 'park' ? finalEntityId : finalParentId, - rideId: finalEntityType === 'ride' ? finalEntityId : undefined, + entityId, + entityType, + parentId, userId: user?.id, }; diff --git a/src/lib/units.ts b/src/lib/units.ts index a28465fd..58f899ce 100644 --- a/src/lib/units.ts +++ b/src/lib/units.ts @@ -6,53 +6,7 @@ export interface UnitPreferences { auto_detect: boolean; } -// Speed conversions -export function convertSpeed(kmh: number, system: MeasurementSystem): number { - if (system === 'imperial') { - return Math.round(kmh * 0.621371); - } - return Math.round(kmh); -} - -// Distance conversions (meters to feet) -export function convertDistance(meters: number, system: MeasurementSystem): number { - if (system === 'imperial') { - return Math.round(meters * 3.28084); - } - return Math.round(meters); -} - -// Height conversions (cm to inches) -export function convertHeight(cm: number, system: MeasurementSystem): number { - if (system === 'imperial') { - return Math.round(cm * 0.393701); - } - return Math.round(cm); -} - -// Reverse conversions (for form inputs - imperial to metric) -export function convertSpeedToMetric(value: number, system: MeasurementSystem): number { - if (system === 'imperial') { - return Math.round(value / 0.621371); - } - return Math.round(value); -} - -export function convertDistanceToMetric(value: number, system: MeasurementSystem): number { - if (system === 'imperial') { - return Math.round(value / 3.28084); - } - return Math.round(value); -} - -export function convertHeightToMetric(value: number, system: MeasurementSystem): number { - if (system === 'imperial') { - return Math.round(value / 0.393701); - } - return Math.round(value); -} - -// Get unit labels +// Get unit labels (helper functions - use getDisplayUnit for conversion logic) export function getSpeedUnit(system: MeasurementSystem): string { return system === 'imperial' ? 'mph' : 'km/h'; } diff --git a/src/pages/RideDetail.tsx b/src/pages/RideDetail.tsx index 7d4c16af..14687115 100644 --- a/src/pages/RideDetail.tsx +++ b/src/pages/RideDetail.tsx @@ -30,7 +30,7 @@ import { } from 'lucide-react'; import { ReviewsSection } from '@/components/reviews/ReviewsSection'; import { MeasurementDisplay } from '@/components/ui/measurement-display'; -import { RidePhotoGallery } from '@/components/rides/RidePhotoGallery'; +import { EntityPhotoGallery } from '@/components/upload/EntityPhotoGallery'; import { RatingDistribution } from '@/components/rides/RatingDistribution'; import { RideHighlights } from '@/components/rides/RideHighlights'; import { SimilarRides } from '@/components/rides/SimilarRides'; @@ -395,8 +395,8 @@ export default function RideDetail() { )} - {ride.former_names && ride.former_names.length > 0 && ( - + {ride.name_history && ride.name_history.length > 0 && ( + )} - diff --git a/src/types/database.ts b/src/types/database.ts index 557e74ea..2bd99178 100644 --- a/src/types/database.ts +++ b/src/types/database.ts @@ -112,8 +112,7 @@ export interface RideModel { category: 'roller_coaster' | 'flat_ride' | 'water_ride' | 'dark_ride' | 'kiddie_ride' | 'transportation'; ride_type: string; description?: string; - technical_specs?: any; // ⚠️ DEPRECATED - Use ride_model_technical_specifications table instead - technical_specifications?: RideModelTechnicalSpec[]; // New relational data + technical_specifications?: RideModelTechnicalSpec[]; } export interface Ride { @@ -138,10 +137,6 @@ export interface Ride { max_height_meters?: number; length_meters?: number; inversions?: number; - coaster_stats?: any; // ⚠️ DEPRECATED - Use ride_coaster_statistics table instead - technical_specs?: any; // ⚠️ DEPRECATED - Use ride_technical_specifications table instead - former_names?: any; // ⚠️ DEPRECATED - Use ride_name_history table instead - // New relational data technical_specifications?: RideTechnicalSpec[]; coaster_statistics?: RideCoasterStat[]; name_history?: RideNameHistory[]; diff --git a/src/types/submissions.ts b/src/types/submissions.ts index 9cac6fba..eed4e2b4 100644 --- a/src/types/submissions.ts +++ b/src/types/submissions.ts @@ -54,10 +54,6 @@ export interface UppyPhotoSubmissionUploadProps { entityId: string; entityType: EntityType; parentId?: string; // Optional parent (e.g., parkId for rides) - - // Deprecated (kept for backwards compatibility) - parkId?: string; - rideId?: string; } /**