● Zion Boggan
repos/Drophawk/frontend/hooks/useSources.ts
zionboggan.com ↗
21 lines · typescript
History for this file →
1
"use client";
2
 
3
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
4
import { api } from "@/lib/api";
5
import { queryKeys } from "@/lib/query";
6
 
7
export function useSources() {
8
  return useQuery({
9
    queryKey: queryKeys.sources,
10
    queryFn: () => api.sources(),
11
    refetchInterval: 20_000,
12
  });
13
}
14
 
15
export function useToggleSource() {
16
  const qc = useQueryClient();
17
  return useMutation({
18
    mutationFn: ({ id, enabled }: { id: string; enabled: boolean }) => api.patchSource(id, enabled),
19
    onSuccess: () => qc.invalidateQueries({ queryKey: queryKeys.sources }),
20
  });
21
}