- added hotlists being displayed
- functionality to delete hotlist
This commit is contained in:
28
src/hooks/useHotListData.ts
Normal file
28
src/hooks/useHotListData.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
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 };
|
||||
};
|
||||
Reference in New Issue
Block a user