mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-20 14:31:12 -05:00
45 lines
1.1 KiB
TypeScript
45 lines
1.1 KiB
TypeScript
import { useQuery } from '@tanstack/react-query';
|
|
import { supabase } from '@/lib/supabaseClient';
|
|
|
|
export interface CoasterStat {
|
|
id: string;
|
|
ride_id: string;
|
|
stat_name: string;
|
|
stat_value: number;
|
|
unit?: string | null;
|
|
category?: string | null;
|
|
description?: string | null;
|
|
display_order: number;
|
|
created_at: string;
|
|
}
|
|
|
|
export function useCoasterStats(rideId: string | undefined) {
|
|
return useQuery({
|
|
queryKey: ['coaster-stats', rideId],
|
|
queryFn: async () => {
|
|
if (!rideId) return [];
|
|
|
|
const { data, error} = await supabase
|
|
.from('ride_coaster_stats')
|
|
.select('*')
|
|
.eq('ride_id', rideId)
|
|
.order('display_order');
|
|
|
|
if (error) throw error;
|
|
|
|
return (data || []).map((stat) => ({
|
|
id: stat.id,
|
|
ride_id: stat.ride_id,
|
|
stat_name: stat.stat_name,
|
|
stat_value: stat.stat_value,
|
|
unit: stat.unit || null,
|
|
category: stat.category || null,
|
|
description: stat.description || null,
|
|
display_order: stat.display_order,
|
|
created_at: stat.created_at,
|
|
})) as CoasterStat[];
|
|
},
|
|
enabled: !!rideId
|
|
});
|
|
}
|