mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-22 22:31:13 -05:00
Refactor code structure and remove redundant changes
This commit is contained in:
51
src-old/hooks/rides/useRideDetail.ts
Normal file
51
src-old/hooks/rides/useRideDetail.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { supabase } from '@/lib/supabaseClient';
|
||||
import { queryKeys } from '@/lib/queryKeys';
|
||||
|
||||
/**
|
||||
* Hook to fetch ride detail with park, manufacturer, and designer
|
||||
*/
|
||||
export function useRideDetail(parkSlug: string | undefined, rideSlug: string | undefined, enabled = true) {
|
||||
return useQuery({
|
||||
queryKey: queryKeys.rides.detail(parkSlug || '', rideSlug || ''),
|
||||
queryFn: async () => {
|
||||
if (!parkSlug || !rideSlug) throw new Error('Both park and ride slugs are required');
|
||||
|
||||
// First get park to find park_id
|
||||
const { data: parkData, error: parkError } = await supabase
|
||||
.from('parks')
|
||||
.select('id')
|
||||
.eq('slug', parkSlug)
|
||||
.maybeSingle();
|
||||
|
||||
if (parkError) throw parkError;
|
||||
if (!parkData) return null;
|
||||
|
||||
// Then get ride details
|
||||
const { data: rideData, error: rideError } = 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();
|
||||
|
||||
if (rideError) throw rideError;
|
||||
|
||||
// Add currentParkId for easier access
|
||||
if (rideData) {
|
||||
return { ...rideData, currentParkId: parkData.id };
|
||||
}
|
||||
|
||||
return rideData;
|
||||
},
|
||||
enabled: enabled && !!parkSlug && !!rideSlug,
|
||||
staleTime: 5 * 60 * 1000, // 5 minutes
|
||||
gcTime: 15 * 60 * 1000, // 15 minutes
|
||||
refetchOnWindowFocus: false,
|
||||
});
|
||||
}
|
||||
34
src-old/hooks/rides/useRides.ts
Normal file
34
src-old/hooks/rides/useRides.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { supabase } from '@/lib/supabaseClient';
|
||||
|
||||
interface UseRidesOptions {
|
||||
enabled?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook to fetch all rides with caching
|
||||
* Loads all rides for client-side filtering
|
||||
*/
|
||||
export function useRides({ enabled = true }: UseRidesOptions = {}) {
|
||||
return useQuery({
|
||||
queryKey: ['rides', 'all'],
|
||||
queryFn: async () => {
|
||||
const { data, error } = await supabase
|
||||
.from('rides')
|
||||
.select(`
|
||||
*,
|
||||
park:parks!inner(name, slug, location:locations(*)),
|
||||
manufacturer:companies!rides_manufacturer_id_fkey(*),
|
||||
designer:companies!rides_designer_id_fkey(*)
|
||||
`)
|
||||
.order('name');
|
||||
|
||||
if (error) throw error;
|
||||
return data || [];
|
||||
},
|
||||
enabled,
|
||||
staleTime: 5 * 60 * 1000, // 5 minutes
|
||||
gcTime: 15 * 60 * 1000, // 15 minutes
|
||||
refetchOnWindowFocus: false,
|
||||
});
|
||||
}
|
||||
50
src-old/hooks/rides/useSimilarRides.ts
Normal file
50
src-old/hooks/rides/useSimilarRides.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { supabase } from '@/lib/supabaseClient';
|
||||
import { queryKeys } from '@/lib/queryKeys';
|
||||
|
||||
/**
|
||||
* Hook to fetch similar rides (same park and category)
|
||||
*/
|
||||
export function useSimilarRides(
|
||||
currentRideId: string | undefined,
|
||||
parkId: string | undefined,
|
||||
category: string | undefined,
|
||||
enabled = true
|
||||
) {
|
||||
return useQuery({
|
||||
queryKey: queryKeys.rides.similar(parkId || '', category || '', currentRideId || ''),
|
||||
queryFn: async () => {
|
||||
if (!currentRideId || !parkId || !category) return [];
|
||||
|
||||
const { data, error } = await supabase
|
||||
.from('rides')
|
||||
.select(`
|
||||
id,
|
||||
name,
|
||||
slug,
|
||||
image_url,
|
||||
average_rating,
|
||||
status,
|
||||
category,
|
||||
description,
|
||||
max_speed_kmh,
|
||||
max_height_meters,
|
||||
duration_seconds,
|
||||
review_count,
|
||||
park:parks!inner(name, slug)
|
||||
`)
|
||||
.eq('park_id', parkId)
|
||||
.eq('category', category)
|
||||
.neq('id', currentRideId)
|
||||
.order('average_rating', { ascending: false })
|
||||
.limit(4);
|
||||
|
||||
if (error) throw error;
|
||||
return data || [];
|
||||
},
|
||||
enabled: enabled && !!currentRideId && !!parkId && !!category,
|
||||
staleTime: 10 * 60 * 1000, // 10 minutes - similar rides rarely change
|
||||
gcTime: 20 * 60 * 1000,
|
||||
refetchOnWindowFocus: false,
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user