Files
thrilltrack-explorer/src-old/hooks/rides/useRides.ts

35 lines
912 B
TypeScript

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,
});
}