- 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:
2025-12-08 10:59:46 +00:00
parent 7cda7d5887
commit 1628048ac5
7 changed files with 111 additions and 5 deletions

View File

@@ -2,6 +2,8 @@ import type { ColourData, PaintedCell, Region } from "../../../../types/types";
import ColourPicker from "./ColourPicker";
import { useCameraFeedContext } from "../../../../app/context/CameraFeedContext";
import { useColourDectection } from "../../hooks/useColourDetection";
import { useBlackBoard } from "../../../../hooks/useBlackBoard";
import { toast } from "sonner";
type RegionSelectorProps = {
regions: Region[];
@@ -13,6 +15,7 @@ type RegionSelectorProps = {
const RegionSelector = ({ regions, selectedRegionIndex, mode, cameraFeedID }: RegionSelectorProps) => {
const { colourMutation } = useColourDectection();
const { state, dispatch } = useCameraFeedContext();
const { blackboardMutation } = useBlackBoard();
const paintedCells = state.paintedCells[cameraFeedID];
const handleChange = (e: { target: { value: string } }) => {
@@ -58,6 +61,10 @@ const RegionSelector = ({ regions, selectedRegionIndex, mode, cameraFeedID }: Re
});
};
const handleResetAll = () => {
dispatch({ type: "RESET_CAMERA_FEED" });
};
const handleSaveclick = () => {
const regions: ColourData[] = [];
const test = Array.from(paintedCells.entries());
@@ -103,12 +110,24 @@ const RegionSelector = ({ regions, selectedRegionIndex, mode, cameraFeedID }: Re
}
colourMutation.mutate({ cameraFeedID, regions: regions });
// Convert Map to plain object for blackboard
const serializableState = {
...state,
paintedCells: {
A: Array.from(state.paintedCells.A.entries()),
B: Array.from(state.paintedCells.B.entries()),
C: Array.from(state.paintedCells.C.entries()),
},
};
blackboardMutation.mutate({ operation: "INSERT", path: `cameraFeed`, value: serializableState });
toast.success("Region data saved successfully!");
};
return (
<div className="flex flex-col gap-4 max-h-[50%]">
<div className="flex flex-col md:flex-row gap-3">
<div className="p-2 border border-gray-600 rounded-lg flex flex-col h-50 w-full">
<div className="p-2 border border-gray-600 rounded-lg flex flex-col h-[10%] w-full">
<h2 className="text-2xl mb-2">Tools</h2>
<div className="flex flex-col">
<label
@@ -208,6 +227,12 @@ const RegionSelector = ({ regions, selectedRegionIndex, mode, cameraFeedID }: Re
>
Reset Region
</button>
<button
onClick={handleResetAll}
className="mt-2 px-4 py-2 border border-red-600 rounded-md text-white bg-red-600 w-full md:w-full hover:bg-red-700 hover:cursor-pointer"
>
Reset All
</button>
</div>
</div>
</div>