import { useWAClient } from "@/app/context"; import { getId } from "@/lib/utils"; import type { WhatsAppClient } from "@client/whatsapp"; import { useQuery, type UseQueryOptions } from "@tanstack/react-query"; async function getChats(client: WhatsAppClient) { return client .listChats({ limit: 500 }) .then((res) => res.map((i) => ({ ...i, id: getId(i.id) }))); } type Response = Awaited>; export function useChats(opt?: Partial) { const { client, isReady } = useWAClient(); return useQuery({ queryKey: ["chats"], queryFn: () => getChats(client), enabled: isReady, ...((opt || {}) as any), }); }