Refactor camera feed handling to support dynamic camera IDs and improve context management
This commit is contained in:
@@ -1,47 +1,38 @@
|
||||
import type { CameraFeedAction, CameraFeedState, PaintedCell } from "../../types/types";
|
||||
import { CAMERA_IDS, DEFAULT_REGIONS, type CameraID } from "../config/cameraConfig";
|
||||
|
||||
export const initialState: CameraFeedState = {
|
||||
cameraFeedID: "A",
|
||||
paintedCells: {
|
||||
A: new Map<string, PaintedCell>(),
|
||||
B: new Map<string, PaintedCell>(),
|
||||
C: new Map<string, PaintedCell>(),
|
||||
},
|
||||
regionsByCamera: {
|
||||
A: [
|
||||
{ name: "Bay 1", brushColour: "#ff0000" },
|
||||
{ name: "Bay 2", brushColour: "#00ff00" },
|
||||
{ name: "Bay 3", brushColour: "#0400ff" },
|
||||
{ name: "Bay 4", brushColour: "#ffff00" },
|
||||
{ name: "Bay 5", brushColour: "#fc35db" },
|
||||
],
|
||||
B: [
|
||||
{ name: "Bay 1", brushColour: "#ff0000" },
|
||||
{ name: "Bay 2", brushColour: "#00ff00" },
|
||||
{ name: "Bay 3", brushColour: "#0400ff" },
|
||||
{ name: "Bay 4", brushColour: "#ffff00" },
|
||||
{ name: "Bay 5", brushColour: "#fc35db" },
|
||||
],
|
||||
C: [
|
||||
{ name: "Bay 1", brushColour: "#ff0000" },
|
||||
{ name: "Bay 2", brushColour: "#00ff00" },
|
||||
{ name: "Bay 3", brushColour: "#0400ff" },
|
||||
{ name: "Bay 4", brushColour: "#ffff00" },
|
||||
{ name: "Bay 5", brushColour: "#fc35db" },
|
||||
],
|
||||
},
|
||||
cameraFeedID: CAMERA_IDS[0],
|
||||
paintedCells: CAMERA_IDS.reduce(
|
||||
(acc, id) => {
|
||||
acc[id] = new Map<string, PaintedCell>();
|
||||
return acc;
|
||||
},
|
||||
{} as Record<string, Map<string, PaintedCell>>,
|
||||
),
|
||||
regionsByCamera: CAMERA_IDS.reduce(
|
||||
(acc, id) => {
|
||||
acc[id] = DEFAULT_REGIONS;
|
||||
return acc;
|
||||
},
|
||||
{} as Record<string, { name: string; brushColour: string }[]>,
|
||||
),
|
||||
|
||||
selectedRegionIndex: 0,
|
||||
modeByCamera: {
|
||||
A: "painter",
|
||||
B: "painter",
|
||||
C: "painter",
|
||||
},
|
||||
zoomLevel: {
|
||||
A: 1,
|
||||
B: 1,
|
||||
C: 1,
|
||||
},
|
||||
modeByCamera: CAMERA_IDS.reduce(
|
||||
(acc, id) => {
|
||||
acc[id] = "painter";
|
||||
return acc;
|
||||
},
|
||||
{} as Record<CameraID, string>,
|
||||
),
|
||||
zoomLevel: CAMERA_IDS.reduce(
|
||||
(acc, id) => {
|
||||
acc[id] = 1;
|
||||
return acc;
|
||||
},
|
||||
{} as Record<CameraID, number>,
|
||||
),
|
||||
};
|
||||
|
||||
export function reducer(state: CameraFeedState, action: CameraFeedAction) {
|
||||
|
||||
Reference in New Issue
Block a user