-
+
Tools
diff --git a/src/features/cameras/components/Video/VideoFeedGridPainter.tsx b/src/features/cameras/components/Video/VideoFeedGridPainter.tsx
index 4e20a59..1c775cc 100644
--- a/src/features/cameras/components/Video/VideoFeedGridPainter.tsx
+++ b/src/features/cameras/components/Video/VideoFeedGridPainter.tsx
@@ -16,7 +16,7 @@ const gap = 0;
const VideoFeedGridPainter = () => {
const { state } = useCameraFeedContext();
const cameraFeedID = state.cameraFeedID;
- const paintedCells = state.paintedCells[cameraFeedID];
+ const paintedCells = state?.paintedCells?.[cameraFeedID];
const regions = state.regionsByCamera[cameraFeedID];
const selectedRegionIndex = state.selectedRegionIndex;
const mode = state.modeByCamera[cameraFeedID];
@@ -135,7 +135,8 @@ const VideoFeedGridPainter = () => {
{
const cells = paintedCells;
- cells.forEach((cell, key) => {
+ if (!cells || cells.size === 0 || !paintLayerRef.current) return;
+ cells?.forEach((cell, key) => {
const [rowStr, colStr] = key.split("-");
const row = Number(rowStr);
const col = Number(colStr);
diff --git a/src/hooks/useBlackBoard.ts b/src/hooks/useBlackBoard.ts
new file mode 100644
index 0000000..638fcae
--- /dev/null
+++ b/src/hooks/useBlackBoard.ts
@@ -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 };
+};
diff --git a/src/types/types.ts b/src/types/types.ts
index 7d7309b..fc0befb 100644
--- a/src/types/types.ts
+++ b/src/types/types.ts
@@ -170,6 +170,13 @@ export type CameraFeedAction =
| {
type: "RESET_PAINTED_CELLS";
payload: { cameraFeedID: "A" | "B" | "C"; paintedCells: Map };
+ }
+ | {
+ type: "SET_CAMERA_FEED_DATA";
+ cameraState: CameraFeedState;
+ }
+ | {
+ type: "RESET_CAMERA_FEED";
};
export type DecodeReading = {
@@ -214,3 +221,9 @@ export type CustomFieldConfig = {
label: string;
value: string;
};
+
+export type BlackBoardOptions = {
+ operation?: string;
+ path?: string;
+ value?: object | string | number | (string | number)[] | null;
+};
diff --git a/src/ui/Card.tsx b/src/ui/Card.tsx
index 11c0fa1..2b814a9 100644
--- a/src/ui/Card.tsx
+++ b/src/ui/Card.tsx
@@ -10,7 +10,7 @@ const Card = ({ children, className }: CardProps) => {
return (