Files
thrilltrack-explorer/src/hooks/homepage/useHomepageOpeningSoon.ts
2025-10-31 13:32:15 +00:00

57 lines
1.8 KiB
TypeScript

import { useQuery } from '@tanstack/react-query';
import { supabase } from '@/integrations/supabase/client';
import { queryKeys } from '@/lib/queryKeys';
import { toDateOnly } from '@/lib/dateUtils';
export function useHomepageOpeningSoonParks(enabled = true) {
return useQuery({
queryKey: queryKeys.homepage.openingSoonParks(),
queryFn: async () => {
const today = new Date();
const sixMonthsFromNow = new Date();
sixMonthsFromNow.setMonth(sixMonthsFromNow.getMonth() + 6);
const { data, error } = await supabase
.from('parks')
.select(`*, location:locations(*), operator:companies!parks_operator_id_fkey(*)`)
.gte('opening_date', toDateOnly(today))
.lte('opening_date', toDateOnly(sixMonthsFromNow))
.order('opening_date', { ascending: true })
.limit(12);
if (error) throw error;
return data || [];
},
enabled,
staleTime: 5 * 60 * 1000,
gcTime: 15 * 60 * 1000,
refetchOnWindowFocus: false,
});
}
export function useHomepageOpeningSoonRides(enabled = true) {
return useQuery({
queryKey: queryKeys.homepage.openingSoonRides(),
queryFn: async () => {
const today = new Date();
const sixMonthsFromNow = new Date();
sixMonthsFromNow.setMonth(sixMonthsFromNow.getMonth() + 6);
const { data, error } = await supabase
.from('rides')
.select(`*, park:parks(*, location:locations(*))`)
.gte('opening_date', toDateOnly(today))
.lte('opening_date', toDateOnly(sixMonthsFromNow))
.order('opening_date', { ascending: true })
.limit(12);
if (error) throw error;
return data || [];
},
enabled,
staleTime: 5 * 60 * 1000,
gcTime: 15 * 60 * 1000,
refetchOnWindowFocus: false,
});
}