Compare commits

...

10 Commits

26 changed files with 531 additions and 43 deletions

View File

@@ -21,13 +21,15 @@
"clsx": "^2.1.1", "clsx": "^2.1.1",
"formik": "^2.4.9", "formik": "^2.4.9",
"konva": "^10.0.11", "konva": "^10.0.11",
"rc-slider": "^11.1.9",
"react": "^19.2.0", "react": "^19.2.0",
"react-dom": "^19.2.0", "react-dom": "^19.2.0",
"react-konva": "^19.2.0", "react-konva": "^19.2.0",
"react-modal": "^3.16.3", "react-modal": "^3.16.3",
"react-tabs": "^6.1.0", "react-tabs": "^6.1.0",
"react-use-websocket": "3.0.0", "react-use-websocket": "3.0.0",
"sonner": "^2.0.7" "sonner": "^2.0.7",
"use-debounce": "^10.0.6"
}, },
"devDependencies": { "devDependencies": {
"@eslint/js": "^9.39.1", "@eslint/js": "^9.39.1",

View File

@@ -1,9 +1,75 @@
import { useReducer, type ReactNode } from "react"; import { useEffect, useReducer, type ReactNode } from "react";
import { CameraFeedContext } from "../context/CameraFeedContext"; import { CameraFeedContext } from "../context/CameraFeedContext";
import { initialState, reducer } from "../reducers/cameraFeedReducer"; import { initialState, reducer } from "../reducers/cameraFeedReducer";
import { useBlackBoard } from "../../hooks/useBlackBoard";
import type { CameraFeedState } from "../../types/types";
import { useCameraZoom } from "../../features/cameras/hooks/useCameraZoom";
export const CameraFeedProvider = ({ children }: { children: ReactNode }) => { export const CameraFeedProvider = ({ children }: { children: ReactNode }) => {
const { blackboardMutation } = useBlackBoard();
const { cameraZoomQuery: cameraZoomQueryA } = useCameraZoom("A");
const { cameraZoomQuery: cameraZoomQueryB } = useCameraZoom("B");
const { cameraZoomQuery: cameraZoomQueryC } = useCameraZoom("C");
const [state, dispatch] = useReducer(reducer, initialState); const [state, dispatch] = useReducer(reducer, initialState);
useEffect(() => {
const fetchBlackBoardData = async () => {
const result = await blackboardMutation.mutateAsync({
operation: "VIEW",
path: "cameraFeed",
});
if (!result?.result || typeof result.result === "string") return;
const cameraFeedData: CameraFeedState = result.result;
const recontructedState = {
...cameraFeedData,
paintedCells: {
A: new Map(cameraFeedData.paintedCells.A),
B: new Map(cameraFeedData.paintedCells.B),
C: new Map(cameraFeedData.paintedCells.C),
},
};
dispatch({ type: "SET_CAMERA_FEED_DATA", cameraState: recontructedState });
};
fetchBlackBoardData();
}, []);
useEffect(() => {
const fetchZoomLevels = async () => {
const [resultA, resultB, resultC] = await Promise.all([
cameraZoomQueryA.refetch(),
cameraZoomQueryB.refetch(),
cameraZoomQueryC.refetch(),
]);
console.log(resultA?.data);
const zoomLevelAnumber = parseFloat(resultA.data?.propPhysCurrent?.value);
const zoomLevelBnumber = parseFloat(resultB.data?.propPhysCurrent?.value);
const zoomLevelCnumber = parseFloat(resultC.data?.propPhysCurrent?.value);
if (resultA.data) {
dispatch({
type: "SET_ZOOM_LEVEL",
payload: { cameraFeedID: "A", zoomLevel: zoomLevelAnumber },
});
}
if (resultB.data) {
dispatch({
type: "SET_ZOOM_LEVEL",
payload: { cameraFeedID: "B", zoomLevel: zoomLevelBnumber },
});
}
if (resultC.data) {
dispatch({
type: "SET_ZOOM_LEVEL",
payload: { cameraFeedID: "C", zoomLevel: zoomLevelCnumber },
});
}
};
fetchZoomLevels();
}, []);
return <CameraFeedContext.Provider value={{ state, dispatch }}>{children}</CameraFeedContext.Provider>; return <CameraFeedContext.Provider value={{ state, dispatch }}>{children}</CameraFeedContext.Provider>;
}; };

View File

@@ -37,6 +37,11 @@ export const initialState: CameraFeedState = {
B: "painter", B: "painter",
C: "painter", C: "painter",
}, },
zoomLevel: {
A: 1,
B: 1,
C: 1,
},
}; };
export function reducer(state: CameraFeedState, action: CameraFeedAction) { export function reducer(state: CameraFeedState, action: CameraFeedAction) {
@@ -98,7 +103,22 @@ export function reducer(state: CameraFeedState, action: CameraFeedAction) {
[state.cameraFeedID]: new Map<string, PaintedCell>(), [state.cameraFeedID]: new Map<string, PaintedCell>(),
}, },
}; };
case "SET_CAMERA_FEED_DATA":
return {
...action.cameraState,
};
case "RESET_CAMERA_FEED":
return {
...initialState,
};
case "SET_ZOOM_LEVEL":
return {
...state,
zoomLevel: {
...state.zoomLevel,
[action.payload.cameraFeedID]: action.payload.zoomLevel,
},
};
default: default:
return state; return state;
} }

View File

@@ -4,22 +4,33 @@ import VideoFeedGridPainter from "./Video/VideoFeedGridPainter";
import CameraSettings from "./CameraSettings/CameraSettings"; import CameraSettings from "./CameraSettings/CameraSettings";
import PlatePatch from "./PlatePatch/SightingPatch"; import PlatePatch from "./PlatePatch/SightingPatch";
import ResetAllModal from "./CameraSettings/resetAllModal/ResetAllModal";
const CameraGrid = () => { const CameraGrid = () => {
const [tabIndex, setTabIndex] = useState(0); const [tabIndex, setTabIndex] = useState(0);
const [isResetModalOpen, setIsResetModalOpen] = useState(false);
return ( return (
<div className="grid grid-cols-1 md:grid-cols-3 gap-4 p-4 h-screen max-h-screen overflow-hidden"> <>
<div className="col-span-2 flex flex-col gap-4"> <div className="grid grid-cols-1 md:grid-cols-3 md:gap-4 p-4 h-screen max-h-screen">
<div className="shrink-0"> <div className="col-span-2 flex flex-col gap-4">
<VideoFeedGridPainter /> <div className="">
</div> <VideoFeedGridPainter />
<div className="flex-1 overflow-hidden"> </div>
<PlatePatch /> <div className="overflow-hidden">
<PlatePatch />
</div>
</div> </div>
<CameraSettings
tabIndex={tabIndex}
setTabIndex={setTabIndex}
isResetAllModalOpen={isResetModalOpen}
handleClose={() => setIsResetModalOpen(false)}
setIsResetModalOpen={setIsResetModalOpen}
/>
</div> </div>
<CameraSettings tabIndex={tabIndex} setTabIndex={setTabIndex} /> <ResetAllModal isResetAllModalOpen={isResetModalOpen} handleClose={() => setIsResetModalOpen(false)} />
</div> </>
); );
}; };

View File

@@ -2,12 +2,16 @@ import { Tabs, Tab, TabList, TabPanel } from "react-tabs";
import { useEffect } from "react"; import { useEffect } from "react";
import { useCameraFeedContext } from "../../../../app/context/CameraFeedContext"; import { useCameraFeedContext } from "../../../../app/context/CameraFeedContext";
import RegionSelector from "./RegionSelector"; import RegionSelector from "./RegionSelector";
import CameraControls from "./cameraControls/CameraControls";
type CameraPanelProps = { type CameraPanelProps = {
tabIndex: number; tabIndex: number;
isResetAllModalOpen: boolean;
handleClose: () => void;
setIsResetModalOpen: React.Dispatch<React.SetStateAction<boolean>>;
}; };
const CameraPanel = ({ tabIndex }: CameraPanelProps) => { const CameraPanel = ({ tabIndex, isResetAllModalOpen, handleClose, setIsResetModalOpen }: CameraPanelProps) => {
const { state, dispatch } = useCameraFeedContext(); const { state, dispatch } = useCameraFeedContext();
const cameraFeedID = state.cameraFeedID; const cameraFeedID = state.cameraFeedID;
const regions = state.regionsByCamera[cameraFeedID]; const regions = state.regionsByCamera[cameraFeedID];
@@ -39,20 +43,19 @@ const CameraPanel = ({ tabIndex }: CameraPanelProps) => {
<Tab>Target Detection</Tab> <Tab>Target Detection</Tab>
<Tab>Camera Controls</Tab> <Tab>Camera Controls</Tab>
</TabList> </TabList>
<TabPanel> <TabPanel>
<RegionSelector <RegionSelector
regions={regions} regions={regions}
selectedRegionIndex={selectedRegionIndex} selectedRegionIndex={selectedRegionIndex}
mode={mode} mode={mode}
cameraFeedID={cameraFeedID} cameraFeedID={cameraFeedID}
isResetAllModalOpen={isResetAllModalOpen}
handleClose={handleClose}
setIsResetModalOpen={setIsResetModalOpen}
/> />
</TabPanel> </TabPanel>
<TabPanel> <TabPanel>
<div className="p-4"> <CameraControls cameraFeedID={cameraFeedID} />
<h2 className="text-lg font-semibold mb-4">Camera Controls</h2>
<p>Controls for camera {cameraFeedID} will go here.</p>
</div>
</TabPanel> </TabPanel>
</Tabs> </Tabs>
); );

View File

@@ -6,11 +6,20 @@ import CameraPanel from "./CameraPanel";
type CameraSettingsProps = { type CameraSettingsProps = {
setTabIndex: (tabIndex: number) => void; setTabIndex: (tabIndex: number) => void;
tabIndex: number; tabIndex: number;
isResetAllModalOpen: boolean;
handleClose: () => void;
setIsResetModalOpen: React.Dispatch<React.SetStateAction<boolean>>;
}; };
const CameraSettings = ({ tabIndex, setTabIndex }: CameraSettingsProps) => { const CameraSettings = ({
tabIndex,
setTabIndex,
isResetAllModalOpen,
handleClose,
setIsResetModalOpen,
}: CameraSettingsProps) => {
return ( return (
<Card className="p-4 w-full h-full max-h-screen "> <Card className="p-4 w-full h-full max-h-screen">
<Tabs <Tabs
selectedTabClassName="bg-gray-300 text-gray-900 font-semibold border-none rounded-sm mb-1" selectedTabClassName="bg-gray-300 text-gray-900 font-semibold border-none rounded-sm mb-1"
className="react-tabs" className="react-tabs"
@@ -22,13 +31,28 @@ const CameraSettings = ({ tabIndex, setTabIndex }: CameraSettingsProps) => {
<Tab>Camera C</Tab> <Tab>Camera C</Tab>
</TabList> </TabList>
<TabPanel> <TabPanel>
<CameraPanel tabIndex={tabIndex} /> <CameraPanel
tabIndex={tabIndex}
isResetAllModalOpen={isResetAllModalOpen}
handleClose={handleClose}
setIsResetModalOpen={setIsResetModalOpen}
/>
</TabPanel> </TabPanel>
<TabPanel> <TabPanel>
<CameraPanel tabIndex={tabIndex} /> <CameraPanel
tabIndex={tabIndex}
isResetAllModalOpen={isResetAllModalOpen}
handleClose={handleClose}
setIsResetModalOpen={setIsResetModalOpen}
/>
</TabPanel> </TabPanel>
<TabPanel> <TabPanel>
<CameraPanel tabIndex={tabIndex} /> <CameraPanel
tabIndex={tabIndex}
isResetAllModalOpen={isResetAllModalOpen}
handleClose={handleClose}
setIsResetModalOpen={setIsResetModalOpen}
/>
</TabPanel> </TabPanel>
</Tabs> </Tabs>
</Card> </Card>

View File

@@ -2,17 +2,31 @@ import type { ColourData, PaintedCell, Region } from "../../../../types/types";
import ColourPicker from "./ColourPicker"; import ColourPicker from "./ColourPicker";
import { useCameraFeedContext } from "../../../../app/context/CameraFeedContext"; import { useCameraFeedContext } from "../../../../app/context/CameraFeedContext";
import { useColourDectection } from "../../hooks/useColourDetection"; import { useColourDectection } from "../../hooks/useColourDetection";
import { useBlackBoard } from "../../../../hooks/useBlackBoard";
import { toast } from "sonner";
type RegionSelectorProps = { type RegionSelectorProps = {
regions: Region[]; regions: Region[];
selectedRegionIndex: number; selectedRegionIndex: number;
mode: string; mode: string;
cameraFeedID: "A" | "B" | "C"; cameraFeedID: "A" | "B" | "C";
isResetAllModalOpen: boolean;
handleClose: () => void;
setIsResetModalOpen: React.Dispatch<React.SetStateAction<boolean>>;
}; };
const RegionSelector = ({ regions, selectedRegionIndex, mode, cameraFeedID }: RegionSelectorProps) => { const RegionSelector = ({
regions,
selectedRegionIndex,
mode,
cameraFeedID,
isResetAllModalOpen,
setIsResetModalOpen,
}: RegionSelectorProps) => {
const { colourMutation } = useColourDectection(); const { colourMutation } = useColourDectection();
const { state, dispatch } = useCameraFeedContext(); const { state, dispatch } = useCameraFeedContext();
const { blackboardMutation } = useBlackBoard();
const paintedCells = state.paintedCells[cameraFeedID]; const paintedCells = state.paintedCells[cameraFeedID];
const handleChange = (e: { target: { value: string } }) => { const handleChange = (e: { target: { value: string } }) => {
@@ -58,6 +72,11 @@ const RegionSelector = ({ regions, selectedRegionIndex, mode, cameraFeedID }: Re
}); });
}; };
const openResetModal = () => {
if (isResetAllModalOpen) return;
setIsResetModalOpen(true);
};
const handleSaveclick = () => { const handleSaveclick = () => {
const regions: ColourData[] = []; const regions: ColourData[] = [];
const test = Array.from(paintedCells.entries()); const test = Array.from(paintedCells.entries());
@@ -103,12 +122,24 @@ const RegionSelector = ({ regions, selectedRegionIndex, mode, cameraFeedID }: Re
} }
colourMutation.mutate({ cameraFeedID, regions: regions }); 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 ( return (
<div className="flex flex-col gap-4 max-h-[50%]"> <div className="flex flex-col gap-4 max-h-[50%]">
<div className="flex flex-row gap-3"> <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> <h2 className="text-2xl mb-2">Tools</h2>
<div className="flex flex-col"> <div className="flex flex-col">
<label <label
@@ -208,6 +239,12 @@ const RegionSelector = ({ regions, selectedRegionIndex, mode, cameraFeedID }: Re
> >
Reset Region Reset Region
</button> </button>
<button
onClick={openResetModal}
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> </div>
</div> </div>

View File

@@ -0,0 +1,42 @@
import { useCameraFeedContext } from "../../../../../app/context/CameraFeedContext";
import SliderComponent from "../../../../../ui/SliderComponent";
import { useCameraZoom } from "../../../hooks/useCameraZoom";
import { useDebouncedCallback } from "use-debounce";
type CameraControlsProps = {
cameraFeedID: "A" | "B" | "C";
};
const CameraControls = ({ cameraFeedID }: CameraControlsProps) => {
const { state, dispatch } = useCameraFeedContext();
const { cameraZoomMutation } = useCameraZoom(cameraFeedID);
const zoomLevel = state.zoomLevel ? state.zoomLevel[cameraFeedID] : 1;
const debouncedMutation = useDebouncedCallback(async (value) => {
await cameraZoomMutation.mutateAsync({
cameraFeedID,
zoomLevel: value as number,
});
}, 1000);
const handleChange = (value: number | number[]) => {
const newZoom = value as number;
dispatch({
type: "SET_ZOOM_LEVEL",
payload: { cameraFeedID: cameraFeedID, zoomLevel: value as number },
});
debouncedMutation(newZoom);
};
return (
<div className="p-2 border border-gray-600 rounded-lg flex flex-col w-full">
<h2 className="text-2xl mb-4">Camera {cameraFeedID}</h2>
<div className="w-[70%] ">
<label htmlFor="zoom">Zoom {zoomLevel} </label>
<SliderComponent id="zoom" onChange={handleChange} value={zoomLevel} min={1} max={3} step={0.1} />
</div>
</div>
);
};
export default CameraControls;

View File

@@ -0,0 +1,55 @@
import { toast } from "sonner";
import { useCameraFeedContext } from "../../../../../app/context/CameraFeedContext";
import { useBlackBoard } from "../../../../../hooks/useBlackBoard";
import ModalComponent from "../../../../../ui/ModalComponent";
type ResetAllModalProps = {
isResetAllModalOpen: boolean;
handleClose: () => void;
};
const ResetAllModal = ({ isResetAllModalOpen, handleClose }: ResetAllModalProps) => {
const { state, dispatch } = useCameraFeedContext();
const { blackboardMutation } = useBlackBoard();
const handleResetAll = async () => {
dispatch({ type: "RESET_CAMERA_FEED" });
handleClose();
const result = await blackboardMutation.mutateAsync({
operation: "INSERT",
path: `cameraFeed`,
value: state,
});
// Need endpoint to reset all target detection painted cells
if (result?.reason === "OK") {
toast.success("All camera settings have been reset to default values.");
}
};
return (
<ModalComponent isModalOpen={isResetAllModalOpen} close={handleClose}>
<div>
<h2 className="text-xl font-bold mb-4">Reset All Camera Settings</h2>
<p className="mb-4">
Are you sure you want to reset all camera settings to their default values? This action cannot be undone.
</p>
<div className="flex justify-end gap-4">
<button
onClick={handleResetAll}
className="bg-red-600 text-white px-4 py-2 rounded hover:bg-red-700 hover:cursor-pointer"
>
Reset
</button>
<button
onClick={handleClose}
className="bg-gray-600 text-white px-4 py-2 rounded hover:bg-gray-700 hover:cursor-pointer "
>
Cancel
</button>
</div>
</div>
</ModalComponent>
);
};
export default ResetAllModal;

View File

@@ -12,7 +12,7 @@ const SightingEntryTable = () => {
if (isLoading) return <span className="text-slate-500">Loading Sighting data</span>; if (isLoading) return <span className="text-slate-500">Loading Sighting data</span>;
return ( return (
<div className="border border-gray-600 rounded-lg overflow-hidden m-2"> <div className="border border-gray-600 rounded-lg m-2">
<div className="overflow-y-auto "> <div className="overflow-y-auto ">
<table className="w-full text-left text-sm"> <table className="w-full text-left text-sm">
<thead className="bg-gray-700/50 text-gray-200 sticky top-0"> <thead className="bg-gray-700/50 text-gray-200 sticky top-0">

View File

@@ -6,9 +6,9 @@ import SightingExitTable from "./SightingExitTable";
const PlatePatch = () => { const PlatePatch = () => {
return ( return (
<Card className="p-4 w-full max-h-[600px] overflow-hidden flex flex-col"> <Card className="p-4 w-full max-h-[600px] flex flex-col md:w-[95%]">
<CardHeader title="Entry / Exit" /> <CardHeader title="Entry / Exit" />
<Tabs defaultIndex={1} className="flex-1 overflow-hidden flex flex-col"> <Tabs defaultIndex={1} className="flex-1 flex flex-col">
<TabList> <TabList>
<Tab>Entry Sightings</Tab> <Tab>Entry Sightings</Tab>
<Tab>Exit Sightings</Tab> <Tab>Exit Sightings</Tab>

View File

@@ -16,7 +16,7 @@ const gap = 0;
const VideoFeedGridPainter = () => { const VideoFeedGridPainter = () => {
const { state } = useCameraFeedContext(); const { state } = useCameraFeedContext();
const cameraFeedID = state.cameraFeedID; const cameraFeedID = state.cameraFeedID;
const paintedCells = state.paintedCells[cameraFeedID]; const paintedCells = state?.paintedCells?.[cameraFeedID];
const regions = state.regionsByCamera[cameraFeedID]; const regions = state.regionsByCamera[cameraFeedID];
const selectedRegionIndex = state.selectedRegionIndex; const selectedRegionIndex = state.selectedRegionIndex;
const mode = state.modeByCamera[cameraFeedID]; const mode = state.modeByCamera[cameraFeedID];
@@ -93,9 +93,15 @@ const VideoFeedGridPainter = () => {
const width = window.innerWidth; const width = window.innerWidth;
const aspectRatio = BACKEND_WIDTH / BACKEND_HEIGHT; const aspectRatio = BACKEND_WIDTH / BACKEND_HEIGHT;
const newWidth = width * 0.6; if (width < 768) {
const newHeight = newWidth / aspectRatio; const newWidth = width * 0.8;
setStageSize({ width: newWidth, height: newHeight }); const newHeight = newWidth / aspectRatio;
setStageSize({ width: newWidth, height: newHeight });
} else {
const newWidth = width * 0.6;
const newHeight = newWidth / aspectRatio;
setStageSize({ width: newWidth, height: newHeight });
}
}; };
handleResize(); handleResize();
@@ -128,7 +134,8 @@ const VideoFeedGridPainter = () => {
<Shape <Shape
sceneFunc={(ctx, shape) => { sceneFunc={(ctx, shape) => {
const cells = paintedCells; 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 [rowStr, colStr] = key.split("-");
const row = Number(rowStr); const row = Number(rowStr);
const col = Number(colStr); const col = Number(colStr);

View File

@@ -0,0 +1,48 @@
import { useQuery, useMutation } from "@tanstack/react-query";
import { CAMBASE } from "../../../utils/config";
import type { CameraZoomConfig } from "../../../types/types";
const fetchZoomLevel = async (cameraFeedID: string) => {
const response = await fetch(`${CAMBASE}/api/fetch-config?id=Camera${cameraFeedID}-onvif-controller`);
if (!response.ok) {
throw new Error("Network response was not ok");
}
return response.json();
};
const postZoomLevel = async (zoomConfig: CameraZoomConfig) => {
const fields = [
{ property: "propPhysCurrent", value: zoomConfig.zoomLevel },
{ property: "propCameraHost", value: "192.168.0.101" },
{ property: "propCameraPort", value: 80 },
{ property: "propCameraUsername", value: "administrator" },
{ property: "propCameraPassword", value: "MAV12345" },
];
const zoomPayload = {
id: `Camera${zoomConfig.cameraFeedID}-onvif-controller`,
fields,
};
console.log(zoomPayload);
const response = await fetch(`${CAMBASE}/api/update-config`, {
method: "POST",
body: JSON.stringify(zoomPayload),
});
if (!response.ok) {
throw new Error("Network response was not ok");
}
return response.json();
};
export const useCameraZoom = (cameraFeedID: "A" | "B" | "C") => {
const cameraZoomQuery = useQuery({
queryKey: ["cameraZoom", cameraFeedID],
queryFn: () => fetchZoomLevel(cameraFeedID),
});
const cameraZoomMutation = useMutation({
mutationKey: ["postCameraZoom"],
mutationFn: (zoomConfig: CameraZoomConfig) => postZoomLevel(zoomConfig),
});
return { cameraZoomQuery, cameraZoomMutation };
};

View File

@@ -2,7 +2,7 @@ import { useQuery } from "@tanstack/react-query";
import { CAMBASE } from "../../../utils/config"; import { CAMBASE } from "../../../utils/config";
const getfeed = async (cameraFeedID: "A" | "B" | "C" | null) => { const getfeed = async (cameraFeedID: "A" | "B" | "C" | null) => {
const response = await fetch(`${CAMBASE}TargetDetectionColour${cameraFeedID}-preview`, { const response = await fetch(`${CAMBASE}/TargetDetectionColour${cameraFeedID}-preview`, {
signal: AbortSignal.timeout(300000), signal: AbortSignal.timeout(300000),
cache: "no-store", cache: "no-store",
}); });

View File

@@ -23,7 +23,7 @@ const ChannelCard = () => {
type="submit" type="submit"
className="w-full md:w-1/4 text-white bg-green-700 hover:bg-green-800 font-small rounded-lg text-sm px-2 py-2.5 hover:cursor-pointer" className="w-full md:w-1/4 text-white bg-green-700 hover:bg-green-800 font-small rounded-lg text-sm px-2 py-2.5 hover:cursor-pointer"
> >
{"Save Changes"} {"Save Settings"}
</button> </button>
</Card> </Card>
); );

View File

@@ -2,6 +2,7 @@ import { Field, useFormikContext } from "formik";
import { useOSDConfig } from "../hooks/useOSDConfig"; import { useOSDConfig } from "../hooks/useOSDConfig";
import OSDFieldToggle from "./OSDFieldToggle"; import OSDFieldToggle from "./OSDFieldToggle";
import type { OSDConfigFields } from "../../../types/types"; import type { OSDConfigFields } from "../../../types/types";
import { toast } from "sonner";
type OSDFieldsProps = { type OSDFieldsProps = {
isOSDLoading: boolean; isOSDLoading: boolean;
@@ -15,7 +16,9 @@ const OSDFields = ({ isOSDLoading }: OSDFieldsProps) => {
const handleSubmit = async (values: OSDConfigFields) => { const handleSubmit = async (values: OSDConfigFields) => {
const result = await osdMutation.mutateAsync(values); const result = await osdMutation.mutateAsync(values);
console.log(result); if (result?.id) {
toast.success("OSD Config updated successfully");
}
}; };
if (isOSDLoading) { if (isOSDLoading) {
@@ -26,7 +29,6 @@ const OSDFields = ({ isOSDLoading }: OSDFieldsProps) => {
<div> <div>
<div className="flex flex-col space-y-4"> <div className="flex flex-col space-y-4">
<div className="p-4 border border-gray-600 rounded-lg flex flex-col space-y-4"> <div className="p-4 border border-gray-600 rounded-lg flex flex-col space-y-4">
<h2 className="text-2xl mb-4">OSD Options</h2>
<div className="flex flex-col space-y-4"> <div className="flex flex-col space-y-4">
{includeKeys.map((key) => ( {includeKeys.map((key) => (
<OSDFieldToggle key={key} value={key} label={key.replace("include", "Include ")} /> <OSDFieldToggle key={key} value={key} label={key.replace("include", "Include ")} />
@@ -59,7 +61,7 @@ const OSDFields = ({ isOSDLoading }: OSDFieldsProps) => {
onClick={() => handleSubmit(values)} onClick={() => handleSubmit(values)}
className="w-full md:w-1/4 text-white bg-green-700 hover:bg-green-800 font-small rounded-lg text-sm px-2 py-2.5 hover:cursor-pointer" className="w-full md:w-1/4 text-white bg-green-700 hover:bg-green-800 font-small rounded-lg text-sm px-2 py-2.5 hover:cursor-pointer"
> >
Submit Save Settings
</button> </button>
</div> </div>
</div> </div>

View File

@@ -1,6 +1,8 @@
import Card from "../../../ui/Card"; import Card from "../../../ui/Card";
import CardHeader from "../../../ui/CardHeader"; import CardHeader from "../../../ui/CardHeader";
import OSDFields from "./OSDFields"; import OSDFields from "./OSDFields";
import { Tab, TabList, TabPanel, Tabs } from "react-tabs";
import "react-tabs/style/react-tabs.css";
type OSDOptionsCardProps = { type OSDOptionsCardProps = {
isOSDLoading: boolean; isOSDLoading: boolean;
@@ -10,7 +12,18 @@ const OSDOptionsCard = ({ isOSDLoading }: OSDOptionsCardProps) => {
return ( return (
<Card className="p-4 flex-1"> <Card className="p-4 flex-1">
<CardHeader title="OSD Payload Options" /> <CardHeader title="OSD Payload Options" />
<OSDFields isOSDLoading={isOSDLoading} /> <Tabs>
<TabList>
<Tab>OSD Settings</Tab>
<Tab>payload Settings</Tab>
</TabList>
<TabPanel>
<OSDFields isOSDLoading={isOSDLoading} />
</TabPanel>
<TabPanel>
<div>payload settings</div>
</TabPanel>
</Tabs>
</Card> </Card>
); );
}; };

View File

@@ -24,7 +24,7 @@ const OutputForms = () => {
const includeCameraName = osdQuery?.data?.propIncludeCameraName?.value.toLowerCase() === "true"; const includeCameraName = osdQuery?.data?.propIncludeCameraName?.value.toLowerCase() === "true";
const overlayPosition = osdQuery?.data?.propOverlayPosition?.value; const overlayPosition = osdQuery?.data?.propOverlayPosition?.value;
const OSDTimestampFormat = osdQuery?.data?.propTimestampFormat?.value; const OSDTimestampFormat = osdQuery?.data?.propTimestampFormat?.value;
console.log(includeVRM);
const format = dispatcherQuery?.data?.propFormat?.value; const format = dispatcherQuery?.data?.propFormat?.value;
const { optionalConstantsQuery, optionalConstantsMutation } = useOptionalConstants(format?.toLowerCase()); const { optionalConstantsQuery, optionalConstantsMutation } = useOptionalConstants(format?.toLowerCase());
const FFID = optionalConstantsQuery?.data?.propFeedIdentifier?.value; const FFID = optionalConstantsQuery?.data?.propFeedIdentifier?.value;

View File

@@ -26,7 +26,6 @@ const postOSDConfig = async (data: OSDConfigFields) => {
fields: fields, fields: fields,
}; };
console.log(osdConfigPayload);
const response = await fetch(`${CAMBASE}/api/update-config`, { const response = await fetch(`${CAMBASE}/api/update-config`, {
method: "POST", method: "POST",
body: JSON.stringify(osdConfigPayload), body: JSON.stringify(osdConfigPayload),

View File

@@ -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 };
};

View File

@@ -5,3 +5,33 @@ body {
color: #fff; color: #fff;
font-family: Arial, Helvetica, sans-serif; font-family: Arial, Helvetica, sans-serif;
} }
/* Modal animations */
.ReactModal__Overlay {
opacity: 0;
transition: opacity 200ms ease-in-out;
}
.ReactModal__Overlay--after-open {
opacity: 1;
}
.ReactModal__Overlay--before-close {
opacity: 0;
}
.ReactModal__Content {
transform: scale(0.9) translateY(-20px);
opacity: 0;
transition: all 200ms ease-in-out;
}
.ReactModal__Content--after-open {
transform: scale(1) translateY(0);
opacity: 1;
}
.ReactModal__Content--before-close {
transform: scale(0.9) translateY(-20px);
opacity: 0;
}

View File

@@ -143,6 +143,11 @@ export type CameraFeedState = {
}; };
tabIndex?: number; tabIndex?: number;
zoomLevel: {
A: number;
B: number;
C: number;
};
}; };
export type CameraFeedAction = export type CameraFeedAction =
@@ -170,6 +175,17 @@ export type CameraFeedAction =
| { | {
type: "RESET_PAINTED_CELLS"; type: "RESET_PAINTED_CELLS";
payload: { cameraFeedID: "A" | "B" | "C"; paintedCells: Map<string, PaintedCell> }; payload: { cameraFeedID: "A" | "B" | "C"; paintedCells: Map<string, PaintedCell> };
}
| {
type: "SET_CAMERA_FEED_DATA";
cameraState: CameraFeedState;
}
| {
type: "RESET_CAMERA_FEED";
}
| {
type: "SET_ZOOM_LEVEL";
payload: { cameraFeedID: "A" | "B" | "C"; zoomLevel: number };
}; };
export type DecodeReading = { export type DecodeReading = {
@@ -214,3 +230,11 @@ export type CustomFieldConfig = {
label: string; label: string;
value: string; value: string;
}; };
export type BlackBoardOptions = {
operation?: string;
path?: string;
value?: object | string | number | (string | number)[] | null;
};
export type CameraZoomConfig = { cameraFeedID: string; zoomLevel: number };

View File

@@ -10,7 +10,7 @@ const Card = ({ children, className }: CardProps) => {
return ( return (
<div <div
className={clsx( className={clsx(
"bg-[#253445] rounded-lg mt-4 shadow-2xl overflow-x-hidden md:row-span-1 px-2 border border-gray-600 ", "bg-[#253445] rounded-lg mt-4 shadow-2xl overflow-x-hidden md:row-span-1 px-2 border border-gray-600 ",
className, className,
)} )}
> >

View File

@@ -13,6 +13,15 @@ const ModalComponent = ({ isModalOpen, children, close }: ModalComponentProps) =
onRequestClose={close} onRequestClose={close}
className="bg-[#1e2a38] p-6 rounded-lg shadow-lg w-[95%] mt-[2%] md:w-[40%] z-100 overflow-y-auto border border-gray-600 max-h-[90%]" className="bg-[#1e2a38] p-6 rounded-lg shadow-lg w-[95%] mt-[2%] md:w-[40%] z-100 overflow-y-auto border border-gray-600 max-h-[90%]"
overlayClassName="fixed inset-0 bg-[#1e2a38]/70 flex justify-center items-start z-100" overlayClassName="fixed inset-0 bg-[#1e2a38]/70 flex justify-center items-start z-100"
closeTimeoutMS={200}
style={{
overlay: {
transition: "opacity 200ms ease-in-out",
},
content: {
transition: "all 200ms ease-in-out",
},
}}
> >
{children} {children}
</Modal> </Modal>

View File

@@ -0,0 +1,24 @@
import Slider from "rc-slider";
import "rc-slider/assets/index.css";
type SliderComponentProps = {
id: string;
onChange: (value: number | number[]) => void;
value?: number;
min?: number;
max?: number;
step?: number;
};
const SliderComponent = ({ id, onChange, value = 0, min = 0, max = 100, step = 1 }: SliderComponentProps) => {
const handleChange = (val: number | number[]) => {
onChange(val);
};
return (
<>
<Slider id={id} onChange={handleChange} value={value} min={min} max={max} step={step} />
</>
);
};
export default SliderComponent;

View File

@@ -226,6 +226,11 @@
"@babel/plugin-transform-modules-commonjs" "^7.27.1" "@babel/plugin-transform-modules-commonjs" "^7.27.1"
"@babel/plugin-transform-typescript" "^7.28.5" "@babel/plugin-transform-typescript" "^7.28.5"
"@babel/runtime@^7.10.1", "@babel/runtime@^7.18.3":
version "7.28.4"
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.28.4.tgz#a70226016fabe25c5783b2f22d3e1c9bc5ca3326"
integrity sha512-Q/N6JNWvIvPnLDvjlE1OUBLPQHH6l3CltCEsHIujp45zQUSSh8K+gHnaEX45yAT1nyngnINhvWtzN+Nb9D8RAQ==
"@babel/template@^7.27.2": "@babel/template@^7.27.2":
version "7.27.2" version "7.27.2"
resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.27.2.tgz#fa78ceed3c4e7b63ebf6cb39e5852fca45f6809d" resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.27.2.tgz#fa78ceed3c4e7b63ebf6cb39e5852fca45f6809d"
@@ -1314,6 +1319,11 @@ chokidar@^3.6.0:
optionalDependencies: optionalDependencies:
fsevents "~2.3.2" fsevents "~2.3.2"
classnames@^2.2.5:
version "2.5.1"
resolved "https://registry.yarnpkg.com/classnames/-/classnames-2.5.1.tgz#ba774c614be0f016da105c858e7159eae8e7687b"
integrity sha512-saHYOzhIQs6wy2sVxTM6bUDsQO4F50V9RQ22qBpEdCW+I+/Wmke2HOl6lS6dTpdxVhb88/I6+Hs+438c3lfUow==
clsx@^2.0.0, clsx@^2.1.1: clsx@^2.0.0, clsx@^2.1.1:
version "2.1.1" version "2.1.1"
resolved "https://registry.yarnpkg.com/clsx/-/clsx-2.1.1.tgz#eed397c9fd8bd882bfb18deab7102049a2f32999" resolved "https://registry.yarnpkg.com/clsx/-/clsx-2.1.1.tgz#eed397c9fd8bd882bfb18deab7102049a2f32999"
@@ -2142,6 +2152,23 @@ queue-microtask@^1.2.2:
resolved "https://registry.yarnpkg.com/queue-microtask/-/queue-microtask-1.2.3.tgz#4929228bbc724dfac43e0efb058caf7b6cfb6243" resolved "https://registry.yarnpkg.com/queue-microtask/-/queue-microtask-1.2.3.tgz#4929228bbc724dfac43e0efb058caf7b6cfb6243"
integrity sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A== integrity sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A==
rc-slider@^11.1.9:
version "11.1.9"
resolved "https://registry.yarnpkg.com/rc-slider/-/rc-slider-11.1.9.tgz#d872130fbf4ec51f28543d62e90451091d6f5208"
integrity sha512-h8IknhzSh3FEM9u8ivkskh+Ef4Yo4JRIY2nj7MrH6GQmrwV6mcpJf5/4KgH5JaVI1H3E52yCdpOlVyGZIeph5A==
dependencies:
"@babel/runtime" "^7.10.1"
classnames "^2.2.5"
rc-util "^5.36.0"
rc-util@^5.36.0:
version "5.44.4"
resolved "https://registry.yarnpkg.com/rc-util/-/rc-util-5.44.4.tgz#89ee9037683cca01cd60f1a6bbda761457dd6ba5"
integrity sha512-resueRJzmHG9Q6rI/DfK6Kdv9/Lfls05vzMs1Sk3M2P+3cJa+MakaZyWY8IPfehVuhPJFKrIY1IK4GqbiaiY5w==
dependencies:
"@babel/runtime" "^7.18.3"
react-is "^18.2.0"
react-dom@^19.2.0: react-dom@^19.2.0:
version "19.2.0" version "19.2.0"
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-19.2.0.tgz#00ed1e959c365e9a9d48f8918377465466ec3af8" resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-19.2.0.tgz#00ed1e959c365e9a9d48f8918377465466ec3af8"
@@ -2159,6 +2186,11 @@ react-is@^16.13.1, react-is@^16.7.0:
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.13.1.tgz#789729a4dc36de2999dc156dd6c1d9c18cea56a4" resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.13.1.tgz#789729a4dc36de2999dc156dd6c1d9c18cea56a4"
integrity sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ== integrity sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==
react-is@^18.2.0:
version "18.3.1"
resolved "https://registry.yarnpkg.com/react-is/-/react-is-18.3.1.tgz#e83557dc12eae63a99e003a46388b1dcbb44db7e"
integrity sha512-/LLMVyas0ljjAtoYiPqYiL8VWXzUUdThrmU5+n20DZv+a+ClRoevUzw5JxU+Ieh5/c87ytoTBV9G1FiKfNJdmg==
react-konva@^19.2.0: react-konva@^19.2.0:
version "19.2.0" version "19.2.0"
resolved "https://registry.yarnpkg.com/react-konva/-/react-konva-19.2.0.tgz#b4cc5d73cd6d642569e4df36a0139996c3dcf8e6" resolved "https://registry.yarnpkg.com/react-konva/-/react-konva-19.2.0.tgz#b4cc5d73cd6d642569e4df36a0139996c3dcf8e6"
@@ -2461,6 +2493,11 @@ uri-js@^4.2.2:
dependencies: dependencies:
punycode "^2.1.0" punycode "^2.1.0"
use-debounce@^10.0.6:
version "10.0.6"
resolved "https://registry.yarnpkg.com/use-debounce/-/use-debounce-10.0.6.tgz#e05060a5e561432ec740c653698f3eb162bd28ec"
integrity sha512-C5OtPyhAZgVoteO9heXMTdW7v/IbFI+8bSVKYCJrSmiWWCLsbUxiBSp4t9v0hNBTGY97bT72ydDIDyGSFWfwXg==
use-sync-external-store@^1.6.0: use-sync-external-store@^1.6.0:
version "1.6.0" version "1.6.0"
resolved "https://registry.yarnpkg.com/use-sync-external-store/-/use-sync-external-store-1.6.0.tgz#b174bfa65cb2b526732d9f2ac0a408027876f32d" resolved "https://registry.yarnpkg.com/use-sync-external-store/-/use-sync-external-store-1.6.0.tgz#b174bfa65cb2b526732d9f2ac0a408027876f32d"