- Enhanced camera feed state management with region handling and mode changes
This commit is contained in:
@@ -7,6 +7,25 @@ export const initialState: CameraFeedState = {
|
||||
B: new Map<string, PaintedCell>(),
|
||||
C: new Map<string, PaintedCell>(),
|
||||
},
|
||||
regionsByCamera: {
|
||||
A: [
|
||||
{ name: "Region 1", brushColour: "#ff0000" },
|
||||
{ name: "Region 2", brushColour: "#00ff00" },
|
||||
{ name: "Region 3", brushColour: "#0400ff" },
|
||||
],
|
||||
B: [
|
||||
{ name: "Region 1", brushColour: "#ff0000" },
|
||||
{ name: "Region 2", brushColour: "#00ff00" },
|
||||
],
|
||||
C: [{ name: "Region 1", brushColour: "#ff0000" }],
|
||||
},
|
||||
|
||||
selectedRegionIndex: 0,
|
||||
modeByCamera: {
|
||||
A: "brush",
|
||||
B: "brush",
|
||||
C: "brush",
|
||||
},
|
||||
};
|
||||
|
||||
export function reducer(state: CameraFeedState, action: CameraFeedAction) {
|
||||
@@ -16,6 +35,60 @@ export function reducer(state: CameraFeedState, action: CameraFeedAction) {
|
||||
...state,
|
||||
cameraFeedID: action.payload,
|
||||
};
|
||||
case "CHANGE_MODE":
|
||||
return {
|
||||
...state,
|
||||
modeByCamera: {
|
||||
...state.modeByCamera,
|
||||
[action.payload.cameraFeedID]: action.payload.mode,
|
||||
},
|
||||
};
|
||||
case "SET_SELECTED_REGION_INDEX":
|
||||
return {
|
||||
...state,
|
||||
selectedRegionIndex: action.payload,
|
||||
};
|
||||
case "SET_SELECTED_REGION_COLOUR":
|
||||
return {
|
||||
...state,
|
||||
regionsByCamera: {
|
||||
...state.regionsByCamera,
|
||||
[action.payload.cameraFeedID]: state.regionsByCamera[action.payload.cameraFeedID].map((region) =>
|
||||
region.name === action.payload.regionName ? { ...region, brushColour: action.payload.newColour } : region,
|
||||
),
|
||||
},
|
||||
};
|
||||
case "ADD_NEW_REGION":
|
||||
return {
|
||||
...state,
|
||||
regionsByCamera: {
|
||||
...state.regionsByCamera,
|
||||
[action.payload.cameraFeedID]: [
|
||||
...state.regionsByCamera[action.payload.cameraFeedID],
|
||||
{ name: action.payload.regionName, brushColour: action.payload.brushColour },
|
||||
],
|
||||
},
|
||||
};
|
||||
case "REMOVE_REGION":
|
||||
console.log(action.payload);
|
||||
return {
|
||||
...state,
|
||||
regionsByCamera: {
|
||||
...state.regionsByCamera,
|
||||
[action.payload.cameraFeedID]: state.regionsByCamera[action.payload.cameraFeedID].filter(
|
||||
(region) => region.name !== action.payload.regionName,
|
||||
),
|
||||
},
|
||||
};
|
||||
case "RESET_PAINTED_CELLS":
|
||||
return {
|
||||
...state,
|
||||
paintedCells: {
|
||||
...state.paintedCells,
|
||||
[state.cameraFeedID]: new Map<string, PaintedCell>(),
|
||||
},
|
||||
};
|
||||
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user