All files / src/hooks/useFeaturedThanks useFeaturedThanks.ts

0% Statements 0/3
0% Branches 0/1
0% Functions 0/2
0% Lines 0/3

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22                                           
/**
 * useFeaturedThanks Hook (Story 7.7 — curated thank-you marquee)
 *
 * React Query hook for the public curated featured thank-you notes. The server randomizes the
 * selection; a generous staleTime keeps the shuffle stable across renders within a visit.
 */
 
import { useQuery, type UseQueryResult } from '@tanstack/react-query';
import * as featuredThanksService from '@/services/featuredThanksService';
import type { FeaturedThanksResponse } from '@/services/featuredThanksService';
 
export const FEATURED_THANKS_QUERY_KEY = ['thanks', 'featured'] as const;
 
/** Up to `limit` random featured thank-you notes (public, cross-event). */
export function useFeaturedThanks(limit = 9): UseQueryResult<FeaturedThanksResponse[], Error> {
  return useQuery({
    queryKey: [...FEATURED_THANKS_QUERY_KEY, limit],
    queryFn: () => featuredThanksService.getFeaturedThanks(limit),
    staleTime: 5 * 60 * 1000,
  });
}