import type { QueryClient } from "@tanstack/react-query";

/**
 * Every cached list that shows community posts: the feed and "view all"
 * (`communityPosts`), the hashtag view and the homepage carousel. A post
 * deleted or edited on its detail page used to linger in them for up to a
 * minute (`staleTime`) after the redirect back to the feed.
 */
const COMMUNITY_FEED_KEYS = [["communityPosts"], ["communityPostsByTag"], ["community-posts-homepage"]] as const;

export function invalidateCommunityFeeds(queryClient: QueryClient): Promise<void> {
  return Promise.all(COMMUNITY_FEED_KEYS.map((queryKey) => queryClient.invalidateQueries({ queryKey: [...queryKey] }))).then(() => undefined);
}
