Files
Mav-Mobile-UI/src/hooks/useHotListData.ts

29 lines
860 B
TypeScript
Raw Normal View History

import { useMutation, useQuery } from "@tanstack/react-query";
import { CAM_BASE } from "../utils/config";
const fetchHotlists = async () => {
const response = await fetch(`${CAM_BASE}/Hotlist-csv-metadata`);
if (!response.ok) throw new Error("Cannot reach hotlist endpoint");
return response.json();
};
const deleteHotlist = async (filename: string) => {
const response = await fetch(`${CAM_BASE}/Hotlist-csv-delete?filename=${filename}`);
if (!response.ok) throw new Error(`Cannot delte hotlist: ${filename}`);
return response.json();
};
export const useHotlistData = () => {
const query = useQuery({
queryKey: ["fetchHotlists"],
queryFn: fetchHotlists,
});
const mutation = useMutation({
mutationKey: ["deleteHotlist"],
mutationFn: (filename: string) => deleteHotlist(filename),
});
return { query, mutation };
};