Refactor camera feed handling to support dynamic camera IDs and improve context management

This commit is contained in:
2025-12-17 14:19:23 +00:00
parent cc8b3a5691
commit 775fce7900
19 changed files with 211 additions and 248 deletions

View File

@@ -1,3 +1,5 @@
import type { CameraID } from "../app/config/cameraConfig";
export type WebSocketContextValue = {
connected: boolean;
send?: (msg: unknown) => void;
@@ -128,57 +130,42 @@ export type OptionalBOF2LaneIDs = {
};
export type CameraFeedState = {
cameraFeedID: "A" | "B" | "C";
paintedCells: {
A: Map<string, PaintedCell>;
B: Map<string, PaintedCell>;
C: Map<string, PaintedCell>;
};
regionsByCamera: {
A: Region[];
B: Region[];
C: Region[];
};
cameraFeedID: CameraID;
paintedCells: Record<CameraID, Map<string, PaintedCell>>;
regionsByCamera: Record<CameraID, Region[]>;
selectedRegionIndex: number;
modeByCamera: {
A: string;
B: string;
C: string;
};
modeByCamera: Record<CameraID, string>;
tabIndex?: number;
zoomLevel: {
A: number;
B: number;
C: number;
};
zoomLevel: Record<CameraID, number>;
};
export type CameraFeedAction =
| {
type: "SET_CAMERA_FEED";
payload: "A" | "B" | "C";
payload: CameraID;
}
| {
type: "CHANGE_MODE";
payload: { cameraFeedID: "A" | "B" | "C"; mode: string };
payload: { cameraFeedID: CameraID; mode: string };
}
| { type: "SET_SELECTED_REGION_INDEX"; payload: number }
| {
type: "SET_SELECTED_REGION_COLOUR";
payload: { cameraFeedID: "A" | "B" | "C"; regionName: string; newColour: string };
payload: { cameraFeedID: CameraID; regionName: string; newColour: string };
}
| {
type: "ADD_NEW_REGION";
payload: { cameraFeedID: "A" | "B" | "C"; regionName: string; brushColour: string };
payload: { cameraFeedID: CameraID; regionName: string; brushColour: string };
}
| {
type: "REMOVE_REGION";
payload: { cameraFeedID: "A" | "B" | "C"; regionName: string };
payload: { cameraFeedID: CameraID; regionName: string };
}
| {
type: "RESET_PAINTED_CELLS";
payload: { cameraFeedID: "A" | "B" | "C"; paintedCells: Map<string, PaintedCell> };
payload: { cameraFeedID: CameraID; paintedCells: Map<string, PaintedCell> };
}
| {
type: "SET_CAMERA_FEED_DATA";
@@ -189,7 +176,7 @@ export type CameraFeedAction =
}
| {
type: "SET_ZOOM_LEVEL";
payload: { cameraFeedID: "A" | "B" | "C"; zoomLevel: number };
payload: { cameraFeedID: CameraID; zoomLevel: number };
};
export type DecodeReading = {
@@ -211,7 +198,7 @@ export type ColourData = {
};
export type ColourDetectionPayload = {
cameraFeedID: "A" | "B" | "C";
cameraFeedID: CameraID;
regions: ColourData[];
};