"use client" import { useQuery } from "@tanstack/react-query" import { createSupabaseBrowserClient } from "@/lib/supabase/client" import { queryKeys } from "./query-keys" interface UnreadCountRow { feed_id: string unread_count: number } export function useUnreadCounts() { const supabaseClient = createSupabaseBrowserClient() return useQuery({ queryKey: queryKeys.unreadCounts.all, queryFn: async () => { const { data, error } = await supabaseClient.rpc("get_unread_counts") if (error) throw error const countsByFeedIdentifier: Record = {} for (const row of (data as UnreadCountRow[]) ?? []) { countsByFeedIdentifier[row.feed_id] = row.unread_count } return countsByFeedIdentifier }, refetchInterval: 60_000, }) }