mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-22 10:31:13 -05:00
Refactor code structure and remove redundant changes
This commit is contained in:
63
src-old/hooks/homepage/useFeaturedParks.ts
Normal file
63
src-old/hooks/homepage/useFeaturedParks.ts
Normal file
@@ -0,0 +1,63 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { supabase } from '@/lib/supabaseClient';
|
||||
import { queryKeys } from '@/lib/queryKeys';
|
||||
|
||||
/**
|
||||
* Hook to fetch featured parks (top rated and most rides)
|
||||
*/
|
||||
export function useFeaturedParks() {
|
||||
const topRated = useQuery({
|
||||
queryKey: queryKeys.homepage.featuredParks.topRated(),
|
||||
queryFn: async () => {
|
||||
const { data, error } = await supabase
|
||||
.from('parks')
|
||||
.select(`
|
||||
*,
|
||||
location:locations(*),
|
||||
operator:companies!parks_operator_id_fkey(*)
|
||||
`)
|
||||
.order('average_rating', { ascending: false })
|
||||
.limit(3);
|
||||
|
||||
if (error) throw error;
|
||||
return data || [];
|
||||
},
|
||||
staleTime: 10 * 60 * 1000, // 10 minutes - featured parks change rarely
|
||||
gcTime: 30 * 60 * 1000,
|
||||
refetchOnWindowFocus: false,
|
||||
});
|
||||
|
||||
const mostRides = useQuery({
|
||||
queryKey: queryKeys.homepage.featuredParks.mostRides(),
|
||||
queryFn: async () => {
|
||||
const { data, error } = await supabase
|
||||
.from('parks')
|
||||
.select(`
|
||||
*,
|
||||
location:locations(*),
|
||||
operator:companies!parks_operator_id_fkey(*)
|
||||
`)
|
||||
.order('ride_count', { ascending: false })
|
||||
.limit(3);
|
||||
|
||||
if (error) throw error;
|
||||
return data || [];
|
||||
},
|
||||
staleTime: 10 * 60 * 1000, // 10 minutes
|
||||
gcTime: 30 * 60 * 1000,
|
||||
refetchOnWindowFocus: false,
|
||||
});
|
||||
|
||||
return {
|
||||
topRated: {
|
||||
data: topRated.data,
|
||||
isLoading: topRated.isLoading,
|
||||
error: topRated.error,
|
||||
},
|
||||
mostRides: {
|
||||
data: mostRides.data,
|
||||
isLoading: mostRides.isLoading,
|
||||
error: mostRides.error,
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user