update camera base URL, enhance alert context, and improve history list functionality
This commit is contained in:
42
src/hooks/useCameraBlackboard.ts
Normal file
42
src/hooks/useCameraBlackboard.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import { useMutation, useQuery } from "@tanstack/react-query";
|
||||
import { CAM_BASE } from "../utils/config";
|
||||
import type { CameraBlackBoardOptions } from "../types/types";
|
||||
|
||||
const getBlackboardData = async () => {
|
||||
const response = await fetch(`${CAM_BASE}/api/blackboard`);
|
||||
if (!response.ok) {
|
||||
throw new Error("Failed to fetch blackboard data");
|
||||
}
|
||||
return response.json();
|
||||
};
|
||||
|
||||
const viewBlackboardData = async (options: CameraBlackBoardOptions) => {
|
||||
const response = await fetch(`${CAM_BASE}/api/blackboard`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(options),
|
||||
});
|
||||
if (!response.ok) {
|
||||
throw new Error("Failed to fetch blackboard data");
|
||||
}
|
||||
return response.json();
|
||||
};
|
||||
|
||||
export const useCameraBlackboard = () => {
|
||||
const query = useQuery({
|
||||
queryKey: ["cameraBlackboard"],
|
||||
queryFn: getBlackboardData,
|
||||
});
|
||||
|
||||
const mutation = useMutation({
|
||||
mutationKey: ["cameraBlackboard"],
|
||||
mutationFn: (options?: CameraBlackBoardOptions) =>
|
||||
viewBlackboardData({
|
||||
operation: options?.operation,
|
||||
path: options?.path,
|
||||
value: options?.value,
|
||||
}),
|
||||
});
|
||||
|
||||
return { query, mutation };
|
||||
};
|
||||
Reference in New Issue
Block a user