- region selector can save settings and painted regions and fetch on load - will add reset all
36 lines
1.0 KiB
TypeScript
36 lines
1.0 KiB
TypeScript
import { useQuery, useMutation } from "@tanstack/react-query";
|
|
import { CAMBASE } from "../utils/config";
|
|
import type { BlackBoardOptions } from "../types/types";
|
|
|
|
const fetchBlackBoardData = async () => {
|
|
const response = await fetch(`${CAMBASE}/api/blackboard`);
|
|
if (!response.ok) {
|
|
throw new Error("Failed to fetch blackboard data");
|
|
}
|
|
return response.json();
|
|
};
|
|
|
|
const viewBlackBoardData = async (options: BlackBoardOptions) => {
|
|
const response = await fetch(`${CAMBASE}/api/blackboard`, {
|
|
method: "POST",
|
|
body: JSON.stringify(options),
|
|
});
|
|
if (!response.ok) {
|
|
throw new Error("Failed to view blackboard data");
|
|
}
|
|
return response.json();
|
|
};
|
|
|
|
export const useBlackBoard = () => {
|
|
const blackboardQuery = useQuery({
|
|
queryKey: ["blackboardData"],
|
|
queryFn: fetchBlackBoardData,
|
|
});
|
|
|
|
const blackboardMutation = useMutation({
|
|
mutationKey: ["viewBlackBoardData"],
|
|
mutationFn: (options: BlackBoardOptions) => viewBlackBoardData(options),
|
|
});
|
|
return { blackboardQuery, blackboardMutation };
|
|
};
|