- added camera black board fetch and post
- region selector can save settings and painted regions and fetch on load - will add reset all
This commit is contained in:
35
src/hooks/useBlackBoard.ts
Normal file
35
src/hooks/useBlackBoard.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
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 };
|
||||
};
|
||||
Reference in New Issue
Block a user