mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-24 19:31:13 -05:00
Refactor: Implement API and cache improvements
This commit is contained in:
@@ -19,36 +19,42 @@ export function ParkCard({ park }: ParkCardProps) {
|
||||
navigate(`/parks/${park.slug}`);
|
||||
};
|
||||
|
||||
// Prefetch park detail data on hover
|
||||
// Smart prefetch - only if not already cached
|
||||
const handleMouseEnter = () => {
|
||||
// Prefetch park detail page data
|
||||
queryClient.prefetchQuery({
|
||||
queryKey: queryKeys.parks.detail(park.slug),
|
||||
queryFn: async () => {
|
||||
const { data } = await supabase
|
||||
.from('parks')
|
||||
.select('*')
|
||||
.eq('slug', park.slug)
|
||||
.single();
|
||||
return data;
|
||||
},
|
||||
staleTime: 5 * 60 * 1000,
|
||||
});
|
||||
// Check if already cached before prefetching
|
||||
const detailCached = queryClient.getQueryData(queryKeys.parks.detail(park.slug));
|
||||
const photosCached = queryClient.getQueryData(queryKeys.photos.entity('park', park.id));
|
||||
|
||||
// Prefetch park photos (first 10)
|
||||
queryClient.prefetchQuery({
|
||||
queryKey: queryKeys.photos.entity('park', park.id),
|
||||
queryFn: async () => {
|
||||
const { data } = await supabase
|
||||
.from('photos')
|
||||
.select('*')
|
||||
.eq('entity_type', 'park')
|
||||
.eq('entity_id', park.id)
|
||||
.limit(10);
|
||||
return data;
|
||||
},
|
||||
staleTime: 5 * 60 * 1000,
|
||||
});
|
||||
if (!detailCached) {
|
||||
queryClient.prefetchQuery({
|
||||
queryKey: queryKeys.parks.detail(park.slug),
|
||||
queryFn: async () => {
|
||||
const { data } = await supabase
|
||||
.from('parks')
|
||||
.select('*')
|
||||
.eq('slug', park.slug)
|
||||
.single();
|
||||
return data;
|
||||
},
|
||||
staleTime: 5 * 60 * 1000,
|
||||
});
|
||||
}
|
||||
|
||||
if (!photosCached) {
|
||||
queryClient.prefetchQuery({
|
||||
queryKey: queryKeys.photos.entity('park', park.id),
|
||||
queryFn: async () => {
|
||||
const { data } = await supabase
|
||||
.from('photos')
|
||||
.select('*')
|
||||
.eq('entity_type', 'park')
|
||||
.eq('entity_id', park.id)
|
||||
.limit(10);
|
||||
return data;
|
||||
},
|
||||
staleTime: 5 * 60 * 1000,
|
||||
});
|
||||
}
|
||||
};
|
||||
const getStatusColor = (status: string) => {
|
||||
switch (status) {
|
||||
|
||||
Reference in New Issue
Block a user