mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-24 09:11:13 -05:00
Refactor homepage content fetching
This commit is contained in:
@@ -68,5 +68,31 @@ export function useQueryInvalidation() {
|
||||
invalidateModerationStats: () => {
|
||||
queryClient.invalidateQueries({ queryKey: queryKeys.moderationStats() });
|
||||
},
|
||||
|
||||
/**
|
||||
* Invalidate homepage data
|
||||
* Call this after creating/updating parks or rides
|
||||
*/
|
||||
invalidateHomepageData: (entityType?: 'parks' | 'rides' | 'all') => {
|
||||
if (!entityType || entityType === 'all') {
|
||||
queryClient.invalidateQueries({ queryKey: ['homepage'] });
|
||||
} else if (entityType === 'parks') {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ['homepage'],
|
||||
predicate: (query) => {
|
||||
const key = query.queryKey[1] as string;
|
||||
return typeof key === 'string' && key.includes('parks');
|
||||
}
|
||||
});
|
||||
} else if (entityType === 'rides') {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ['homepage'],
|
||||
predicate: (query) => {
|
||||
const key = query.queryKey[1] as string;
|
||||
return typeof key === 'string' && key.includes('rides');
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -14,5 +14,24 @@ export const queryKeys = {
|
||||
moderationQueue: (config: Record<string, any>) => ['moderation-queue', config] as const,
|
||||
moderationStats: () => ['moderation-stats'] as const,
|
||||
|
||||
// Homepage queries
|
||||
homepage: {
|
||||
trendingParks: () => ['homepage', 'trending-parks'] as const,
|
||||
trendingRides: () => ['homepage', 'trending-rides'] as const,
|
||||
recentParks: () => ['homepage', 'recent-parks'] as const,
|
||||
recentRides: () => ['homepage', 'recent-rides'] as const,
|
||||
recentChanges: () => ['homepage', 'recent-changes'] as const,
|
||||
recentlyOpenedParks: () => ['homepage', 'recently-opened-parks'] as const,
|
||||
recentlyOpenedRides: () => ['homepage', 'recently-opened-rides'] as const,
|
||||
highestRatedParks: () => ['homepage', 'highest-rated-parks'] as const,
|
||||
highestRatedRides: () => ['homepage', 'highest-rated-rides'] as const,
|
||||
openingSoonParks: () => ['homepage', 'opening-soon-parks'] as const,
|
||||
openingSoonRides: () => ['homepage', 'opening-soon-rides'] as const,
|
||||
closingSoonParks: () => ['homepage', 'closing-soon-parks'] as const,
|
||||
closingSoonRides: () => ['homepage', 'closing-soon-rides'] as const,
|
||||
recentlyClosedParks: () => ['homepage', 'recently-closed-parks'] as const,
|
||||
recentlyClosedRides: () => ['homepage', 'recently-closed-rides'] as const,
|
||||
},
|
||||
|
||||
// Add more query keys as needed
|
||||
} as const;
|
||||
|
||||
Reference in New Issue
Block a user