mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-22 12:31:12 -05:00
Refactor: Implement complete plan
This commit is contained in:
44
src/hooks/useCoasterStats.ts
Normal file
44
src/hooks/useCoasterStats.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { supabase } from '@/integrations/supabase/client';
|
||||
|
||||
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 as any)
|
||||
.from('ride_coaster_stats')
|
||||
.select('*')
|
||||
.eq('ride_id', rideId)
|
||||
.order('display_order');
|
||||
|
||||
if (error) throw error;
|
||||
|
||||
return (data || []).map((stat: any) => ({
|
||||
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
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user