mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-23 12:11:13 -05:00
584 lines
23 KiB
TypeScript
584 lines
23 KiB
TypeScript
import { useState, useEffect } from 'react';
|
|
import { useParams, useNavigate } from 'react-router-dom';
|
|
import { Header } from '@/components/layout/Header';
|
|
import { Button } from '@/components/ui/button';
|
|
import { Badge } from '@/components/ui/badge';
|
|
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
|
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs';
|
|
import { Separator } from '@/components/ui/separator';
|
|
import {
|
|
MapPin,
|
|
Star,
|
|
Clock,
|
|
Zap,
|
|
ArrowLeft,
|
|
Users,
|
|
Ruler,
|
|
Timer,
|
|
TrendingUp,
|
|
Camera,
|
|
Heart,
|
|
RotateCcw,
|
|
AlertTriangle,
|
|
FerrisWheel,
|
|
Waves,
|
|
Theater,
|
|
Train
|
|
} from 'lucide-react';
|
|
import { ReviewsSection } from '@/components/reviews/ReviewsSection';
|
|
import { MeasurementDisplay } from '@/components/ui/measurement-display';
|
|
import { RidePhotoGallery } from '@/components/rides/RidePhotoGallery';
|
|
import { Ride } from '@/types/database';
|
|
import { supabase } from '@/integrations/supabase/client';
|
|
|
|
export default function RideDetail() {
|
|
const { parkSlug, rideSlug } = useParams<{ parkSlug: string; rideSlug: string }>();
|
|
const navigate = useNavigate();
|
|
const [ride, setRide] = useState<Ride | null>(null);
|
|
const [loading, setLoading] = useState(true);
|
|
|
|
useEffect(() => {
|
|
if (parkSlug && rideSlug) {
|
|
fetchRideData();
|
|
}
|
|
}, [parkSlug, rideSlug]);
|
|
|
|
const fetchRideData = async () => {
|
|
try {
|
|
// First get park to find park_id
|
|
const { data: parkData } = await supabase
|
|
.from('parks')
|
|
.select('id')
|
|
.eq('slug', parkSlug)
|
|
.maybeSingle();
|
|
|
|
if (parkData) {
|
|
// Then get ride details
|
|
const { data: rideData } = await supabase
|
|
.from('rides')
|
|
.select(`
|
|
*,
|
|
park:parks!inner(id, name, slug, location:locations(*)),
|
|
manufacturer:companies!rides_manufacturer_id_fkey(*),
|
|
designer:companies!rides_designer_id_fkey(*)
|
|
`)
|
|
.eq('park_id', parkData.id)
|
|
.eq('slug', rideSlug)
|
|
.maybeSingle();
|
|
|
|
setRide(rideData);
|
|
}
|
|
} catch (error) {
|
|
console.error('Error fetching ride data:', error);
|
|
} finally {
|
|
setLoading(false);
|
|
}
|
|
};
|
|
|
|
const getStatusColor = (status: string) => {
|
|
switch (status) {
|
|
case 'operating': return 'bg-green-500/20 text-green-400 border-green-500/30';
|
|
case 'seasonal': return 'bg-yellow-500/20 text-yellow-400 border-yellow-500/30';
|
|
case 'under_construction': return 'bg-blue-500/20 text-blue-400 border-blue-500/30';
|
|
default: return 'bg-red-500/20 text-red-400 border-red-500/30';
|
|
}
|
|
};
|
|
|
|
const getRideIcon = (category: string) => {
|
|
switch (category) {
|
|
case 'roller_coaster': return <FerrisWheel className="w-20 h-20" />;
|
|
case 'water_ride': return <Waves className="w-20 h-20" />;
|
|
case 'dark_ride': return <Theater className="w-20 h-20" />;
|
|
case 'flat_ride': return <FerrisWheel className="w-20 h-20" />;
|
|
case 'kiddie_ride': return <FerrisWheel className="w-20 h-20" />;
|
|
case 'transportation': return <Train className="w-20 h-20" />;
|
|
default: return <FerrisWheel className="w-20 h-20" />;
|
|
}
|
|
};
|
|
|
|
const formatCategory = (category: string) => {
|
|
return category.split('_').map(word =>
|
|
word.charAt(0).toUpperCase() + word.slice(1)
|
|
).join(' ');
|
|
};
|
|
|
|
if (loading) {
|
|
return (
|
|
<div className="min-h-screen bg-background">
|
|
<Header />
|
|
<div className="container mx-auto px-4 py-8">
|
|
<div className="animate-pulse space-y-6">
|
|
<div className="h-64 bg-muted rounded-lg"></div>
|
|
<div className="h-8 bg-muted rounded w-1/2"></div>
|
|
<div className="h-4 bg-muted rounded w-1/3"></div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
if (!ride || !ride.park) {
|
|
return (
|
|
<div className="min-h-screen bg-background">
|
|
<Header />
|
|
<div className="container mx-auto px-4 py-8">
|
|
<div className="text-center py-12">
|
|
<h1 className="text-2xl font-bold mb-4">Ride Not Found</h1>
|
|
<p className="text-muted-foreground mb-6">
|
|
The ride you're looking for doesn't exist or has been removed.
|
|
</p>
|
|
<Button onClick={() => navigate('/rides')}>
|
|
<ArrowLeft className="w-4 h-4 mr-2" />
|
|
Back to Rides
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<div className="min-h-screen bg-background">
|
|
<Header />
|
|
|
|
<main className="container mx-auto px-4 py-8">
|
|
{/* Back Button */}
|
|
<Button
|
|
variant="ghost"
|
|
onClick={() => navigate(`/parks/${ride.park?.slug}`)}
|
|
className="mb-6"
|
|
>
|
|
<ArrowLeft className="w-4 h-4 mr-2" />
|
|
Back to {ride.park?.name}
|
|
</Button>
|
|
|
|
{/* Hero Section */}
|
|
<div className="relative mb-8">
|
|
<div className="aspect-[21/9] bg-gradient-to-br from-primary/20 via-secondary/20 to-accent/20 rounded-lg overflow-hidden relative">
|
|
{ride.image_url ? (
|
|
<img
|
|
src={ride.image_url}
|
|
alt={ride.name}
|
|
className="w-full h-full object-cover"
|
|
/>
|
|
) : (
|
|
<div className="flex items-center justify-center h-full">
|
|
<div className="opacity-50">
|
|
{getRideIcon(ride.category)}
|
|
</div>
|
|
</div>
|
|
)}
|
|
<div className="absolute inset-0 bg-gradient-to-t from-black/60 via-transparent to-transparent" />
|
|
|
|
{/* Ride Title Overlay */}
|
|
<div className="absolute bottom-0 left-0 right-0 p-8">
|
|
<div className="flex items-end justify-between">
|
|
<div>
|
|
<div className="flex items-center gap-3 mb-2">
|
|
<Badge className={`${getStatusColor(ride.status)} border`}>
|
|
{ride.status.replace('_', ' ').toUpperCase()}
|
|
</Badge>
|
|
<Badge variant="outline" className="bg-black/20 text-white border-white/20">
|
|
{formatCategory(ride.category)}
|
|
</Badge>
|
|
</div>
|
|
<h1 className="text-4xl md:text-6xl font-bold text-white mb-2">
|
|
{ride.name}
|
|
</h1>
|
|
<div className="flex items-center text-white/90 text-lg">
|
|
<MapPin className="w-5 h-5 mr-2" />
|
|
{ride.park.name}
|
|
</div>
|
|
</div>
|
|
|
|
{ride.average_rating > 0 && (
|
|
<div className="bg-black/20 backdrop-blur-sm rounded-lg p-4 text-center">
|
|
<div className="flex items-center gap-2 text-white mb-1">
|
|
<Star className="w-5 h-5 fill-yellow-400 text-yellow-400" />
|
|
<span className="text-2xl font-bold">{ride.average_rating.toFixed(1)}</span>
|
|
</div>
|
|
<div className="text-white/70 text-sm">
|
|
{ride.review_count} reviews
|
|
</div>
|
|
</div>
|
|
)}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
{/* Quick Stats */}
|
|
<div className="grid grid-cols-2 md:grid-cols-4 lg:grid-cols-6 gap-4 mb-8">
|
|
{ride.max_speed_kmh && (
|
|
<Card>
|
|
<CardContent className="p-4 text-center">
|
|
<Zap className="w-6 h-6 text-primary mx-auto mb-2" />
|
|
<div className="text-2xl font-bold text-primary">
|
|
<MeasurementDisplay value={ride.max_speed_kmh} type="speed" />
|
|
</div>
|
|
</CardContent>
|
|
</Card>
|
|
)}
|
|
|
|
{ride.max_height_meters && (
|
|
<Card>
|
|
<CardContent className="p-4 text-center">
|
|
<TrendingUp className="w-6 h-6 text-accent mx-auto mb-2" />
|
|
<div className="text-2xl font-bold text-accent">
|
|
<MeasurementDisplay value={ride.max_height_meters} type="distance" />
|
|
</div>
|
|
</CardContent>
|
|
</Card>
|
|
)}
|
|
|
|
{ride.length_meters && (
|
|
<Card>
|
|
<CardContent className="p-4 text-center">
|
|
<Ruler className="w-6 h-6 text-secondary mx-auto mb-2" />
|
|
<div className="text-2xl font-bold text-secondary">
|
|
<MeasurementDisplay value={ride.length_meters} type="distance" />
|
|
</div>
|
|
<div className="text-sm text-muted-foreground">long</div>
|
|
</CardContent>
|
|
</Card>
|
|
)}
|
|
|
|
{ride.duration_seconds && (
|
|
<Card>
|
|
<CardContent className="p-4 text-center">
|
|
<Timer className="w-6 h-6 text-primary mx-auto mb-2" />
|
|
<div className="text-2xl font-bold text-primary">{Math.floor(ride.duration_seconds / 60)}:{(ride.duration_seconds % 60).toString().padStart(2, '0')}</div>
|
|
<div className="text-sm text-muted-foreground">duration</div>
|
|
</CardContent>
|
|
</Card>
|
|
)}
|
|
|
|
{ride.capacity_per_hour && (
|
|
<Card>
|
|
<CardContent className="p-4 text-center">
|
|
<Users className="w-6 h-6 text-accent mx-auto mb-2" />
|
|
<div className="text-2xl font-bold text-accent">{ride.capacity_per_hour}</div>
|
|
<div className="text-sm text-muted-foreground">riders/hour</div>
|
|
</CardContent>
|
|
</Card>
|
|
)}
|
|
|
|
{ride.inversions && ride.inversions > 0 && (
|
|
<Card>
|
|
<CardContent className="p-4 text-center">
|
|
<RotateCcw className="w-6 h-6 text-accent mx-auto mb-2" />
|
|
<div className="text-2xl font-bold">{ride.inversions}</div>
|
|
<div className="text-sm text-muted-foreground">inversions</div>
|
|
</CardContent>
|
|
</Card>
|
|
)}
|
|
|
|
{/* New roller coaster specific stats */}
|
|
{ride.drop_height_meters && (
|
|
<Card>
|
|
<CardContent className="p-4 text-center">
|
|
<TrendingDown className="w-6 h-6 mx-auto mb-2 text-destructive" />
|
|
<div className="text-2xl font-bold text-destructive">
|
|
<MeasurementDisplay value={ride.drop_height_meters} type="distance" />
|
|
</div>
|
|
<div className="text-sm text-muted-foreground">drop</div>
|
|
</CardContent>
|
|
</Card>
|
|
)}
|
|
|
|
{ride.max_g_force && (
|
|
<Card>
|
|
<CardContent className="p-4 text-center">
|
|
<Zap className="w-6 h-6 mx-auto mb-2 text-warning" />
|
|
<div className="text-2xl font-bold text-warning">{ride.max_g_force}g</div>
|
|
<div className="text-sm text-muted-foreground">max G-force</div>
|
|
</CardContent>
|
|
</Card>
|
|
)}
|
|
</div>
|
|
|
|
{/* Requirements & Warnings */}
|
|
{(ride.height_requirement || ride.age_requirement) && (
|
|
<Card className="mb-8 border-orange-200 bg-orange-50 dark:border-orange-800 dark:bg-orange-950">
|
|
<CardContent className="p-4">
|
|
<div className="flex items-start gap-3">
|
|
<AlertTriangle className="w-5 h-5 text-orange-600 mt-0.5" />
|
|
<div>
|
|
<h3 className="font-semibold text-orange-800 dark:text-orange-200 mb-2">
|
|
Ride Requirements
|
|
</h3>
|
|
<div className="text-sm space-y-1">
|
|
{ride.height_requirement && (
|
|
<div>Minimum height: <MeasurementDisplay value={ride.height_requirement} type="height" /></div>
|
|
)}
|
|
{ride.age_requirement && (
|
|
<div>Minimum age: {ride.age_requirement} years</div>
|
|
)}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</CardContent>
|
|
</Card>
|
|
)}
|
|
|
|
{/* Main Content */}
|
|
<Tabs defaultValue="overview" className="w-full">
|
|
<TabsList className="grid w-full grid-cols-4">
|
|
<TabsTrigger value="overview">Overview</TabsTrigger>
|
|
<TabsTrigger value="specs">Specifications</TabsTrigger>
|
|
<TabsTrigger value="reviews">Reviews</TabsTrigger>
|
|
<TabsTrigger value="photos">Photos</TabsTrigger>
|
|
</TabsList>
|
|
|
|
<TabsContent value="overview" className="mt-6">
|
|
<div className="grid lg:grid-cols-3 gap-6">
|
|
<div className="lg:col-span-2 space-y-6">
|
|
{/* Description */}
|
|
{ride.description && (
|
|
<Card>
|
|
<CardHeader>
|
|
<CardTitle>About {ride.name}</CardTitle>
|
|
</CardHeader>
|
|
<CardContent>
|
|
<p className="text-muted-foreground leading-relaxed">
|
|
{ride.description}
|
|
</p>
|
|
</CardContent>
|
|
</Card>
|
|
)}
|
|
</div>
|
|
|
|
<div className="space-y-6">
|
|
{/* Ride Information */}
|
|
<Card>
|
|
<CardHeader>
|
|
<CardTitle>Ride Information</CardTitle>
|
|
</CardHeader>
|
|
<CardContent className="space-y-4">
|
|
<div className="flex items-center gap-3">
|
|
<div className="flex items-center">{getRideIcon(ride.category)}</div>
|
|
<div>
|
|
<div className="font-medium">Category</div>
|
|
<div className="text-sm text-muted-foreground">
|
|
{formatCategory(ride.category)}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
{ride.opening_date && (
|
|
<div className="flex items-center gap-3">
|
|
<Clock className="w-4 h-4 text-muted-foreground" />
|
|
<div>
|
|
<div className="font-medium">Opened</div>
|
|
<div className="text-sm text-muted-foreground">
|
|
{new Date(ride.opening_date).getFullYear()}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
)}
|
|
|
|
{ride.manufacturer && (
|
|
<div className="flex items-center gap-3">
|
|
<Users className="w-4 h-4 text-muted-foreground" />
|
|
<div>
|
|
<div className="font-medium">Manufacturer</div>
|
|
<div className="text-sm text-muted-foreground">
|
|
{ride.manufacturer.name}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
)}
|
|
|
|
{ride.designer && (
|
|
<div className="flex items-center gap-3">
|
|
<Users className="w-4 h-4 text-muted-foreground" />
|
|
<div>
|
|
<div className="font-medium">Designer</div>
|
|
<div className="text-sm text-muted-foreground">
|
|
{ride.designer.name}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
)}
|
|
|
|
{/* Roller Coaster Specific Info */}
|
|
{ride.category === 'roller_coaster' && (ride.coaster_type || ride.seating_type || ride.intensity_level) && (
|
|
<>
|
|
<Separator />
|
|
<div className="space-y-3">
|
|
<div className="font-medium">Coaster Details</div>
|
|
{ride.coaster_type && (
|
|
<div className="flex items-center gap-3">
|
|
<div className="text-lg">🎢</div>
|
|
<div>
|
|
<div className="font-medium">Type</div>
|
|
<div className="text-sm text-muted-foreground">
|
|
{ride.coaster_type.charAt(0).toUpperCase() + ride.coaster_type.slice(1)}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
)}
|
|
{ride.seating_type && (
|
|
<div className="flex items-center gap-3">
|
|
<div className="text-lg">💺</div>
|
|
<div>
|
|
<div className="font-medium">Seating</div>
|
|
<div className="text-sm text-muted-foreground">
|
|
{ride.seating_type.replace('_', ' ').replace(/\b\w/g, l => l.toUpperCase())}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
)}
|
|
{ride.intensity_level && (
|
|
<div className="flex items-center gap-3">
|
|
<div className="text-lg">🔥</div>
|
|
<div>
|
|
<div className="font-medium">Intensity</div>
|
|
<div className="text-sm text-muted-foreground">
|
|
{ride.intensity_level.charAt(0).toUpperCase() + ride.intensity_level.slice(1)}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
)}
|
|
</div>
|
|
</>
|
|
)}
|
|
|
|
<Separator />
|
|
|
|
<div className="space-y-2">
|
|
<div className="font-medium">Located at</div>
|
|
<Button
|
|
variant="outline"
|
|
className="w-full justify-start"
|
|
onClick={() => navigate(`/parks/${ride.park?.slug}`)}
|
|
>
|
|
<MapPin className="w-4 h-4 mr-2" />
|
|
{ride.park.name}
|
|
</Button>
|
|
</div>
|
|
</CardContent>
|
|
</Card>
|
|
</div>
|
|
</div>
|
|
</TabsContent>
|
|
|
|
<TabsContent value="specs" className="mt-6">
|
|
<div className="grid md:grid-cols-2 gap-6">
|
|
{/* Performance Stats */}
|
|
<Card>
|
|
<CardHeader>
|
|
<CardTitle>Performance</CardTitle>
|
|
</CardHeader>
|
|
<CardContent className="space-y-4">
|
|
{ride.max_speed_kmh && (
|
|
<div className="flex justify-between">
|
|
<span>Maximum Speed</span>
|
|
<span className="font-medium">
|
|
<MeasurementDisplay value={ride.max_speed_kmh} type="speed" />
|
|
</span>
|
|
</div>
|
|
)}
|
|
{ride.max_height_meters && (
|
|
<div className="flex justify-between">
|
|
<span>Maximum Height</span>
|
|
<span className="font-medium">
|
|
<MeasurementDisplay value={ride.max_height_meters} type="distance" />
|
|
</span>
|
|
</div>
|
|
)}
|
|
{ride.length_meters && (
|
|
<div className="flex justify-between">
|
|
<span>Track Length</span>
|
|
<span className="font-medium">
|
|
<MeasurementDisplay value={ride.length_meters} type="distance" />
|
|
</span>
|
|
</div>
|
|
)}
|
|
{ride.duration_seconds && (
|
|
<div className="flex justify-between">
|
|
<span>Ride Duration</span>
|
|
<span className="font-medium">{Math.floor(ride.duration_seconds / 60)}:{(ride.duration_seconds % 60).toString().padStart(2, '0')}</span>
|
|
</div>
|
|
)}
|
|
{ride.inversions && ride.inversions > 0 && (
|
|
<div className="flex justify-between">
|
|
<span>Inversions</span>
|
|
<span className="font-medium">{ride.inversions}</span>
|
|
</div>
|
|
)}
|
|
{ride.drop_height_meters && (
|
|
<div className="flex justify-between">
|
|
<span>Drop Height</span>
|
|
<span className="font-medium">
|
|
<MeasurementDisplay value={ride.drop_height_meters} type="distance" />
|
|
</span>
|
|
</div>
|
|
)}
|
|
{ride.max_g_force && (
|
|
<div className="flex justify-between">
|
|
<span>Maximum G-Force</span>
|
|
<span className="font-medium">{ride.max_g_force}g</span>
|
|
</div>
|
|
)}
|
|
</CardContent>
|
|
</Card>
|
|
|
|
{/* Operational Info */}
|
|
<Card>
|
|
<CardHeader>
|
|
<CardTitle>Operational Details</CardTitle>
|
|
</CardHeader>
|
|
<CardContent className="space-y-4">
|
|
{ride.capacity_per_hour && (
|
|
<div className="flex justify-between">
|
|
<span>Capacity</span>
|
|
<span className="font-medium">{ride.capacity_per_hour} riders/hour</span>
|
|
</div>
|
|
)}
|
|
{ride.height_requirement && (
|
|
<div className="flex justify-between">
|
|
<span>Height Requirement</span>
|
|
<span className="font-medium">
|
|
<MeasurementDisplay value={ride.height_requirement} type="height" /> minimum
|
|
</span>
|
|
</div>
|
|
)}
|
|
{ride.age_requirement && (
|
|
<div className="flex justify-between">
|
|
<span>Age Requirement</span>
|
|
<span className="font-medium">{ride.age_requirement}+ years</span>
|
|
</div>
|
|
)}
|
|
<div className="flex justify-between">
|
|
<span>Status</span>
|
|
<Badge className={getStatusColor(ride.status)}>
|
|
{ride.status.replace('_', ' ')}
|
|
</Badge>
|
|
</div>
|
|
</CardContent>
|
|
</Card>
|
|
</div>
|
|
</TabsContent>
|
|
|
|
<TabsContent value="reviews" className="mt-6">
|
|
<ReviewsSection
|
|
entityType="ride"
|
|
entityId={ride.id}
|
|
entityName={ride.name}
|
|
averageRating={ride.average_rating}
|
|
reviewCount={ride.review_count}
|
|
/>
|
|
</TabsContent>
|
|
|
|
<TabsContent value="photos" className="mt-6">
|
|
<RidePhotoGallery
|
|
rideId={ride.id}
|
|
rideName={ride.name}
|
|
/>
|
|
</TabsContent>
|
|
</Tabs>
|
|
</main>
|
|
</div>
|
|
);
|
|
} |