Compare commits

...

4 Commits

11 changed files with 181 additions and 23 deletions

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 md:gap-4 p-4 h-screen max-h-screen"> <>
<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=""> <div className="col-span-2 flex flex-col gap-4">
<VideoFeedGridPainter /> <div className="">
</div> <VideoFeedGridPainter />
<div className="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

@@ -5,9 +5,12 @@ import RegionSelector from "./RegionSelector";
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];
@@ -45,6 +48,9 @@ const CameraPanel = ({ tabIndex }: CameraPanelProps) => {
selectedRegionIndex={selectedRegionIndex} selectedRegionIndex={selectedRegionIndex}
mode={mode} mode={mode}
cameraFeedID={cameraFeedID} cameraFeedID={cameraFeedID}
isResetAllModalOpen={isResetAllModalOpen}
handleClose={handleClose}
setIsResetModalOpen={setIsResetModalOpen}
/> />
</TabPanel> </TabPanel>
<TabPanel> <TabPanel>

View File

@@ -6,9 +6,18 @@ 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
@@ -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

@@ -10,9 +10,20 @@ type RegionSelectorProps = {
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 { blackboardMutation } = useBlackBoard();
@@ -61,8 +72,9 @@ const RegionSelector = ({ regions, selectedRegionIndex, mode, cameraFeedID }: Re
}); });
}; };
const handleResetAll = () => { const openResetModal = () => {
dispatch({ type: "RESET_CAMERA_FEED" }); if (isResetAllModalOpen) return;
setIsResetModalOpen(true);
}; };
const handleSaveclick = () => { const handleSaveclick = () => {
@@ -228,7 +240,7 @@ const RegionSelector = ({ regions, selectedRegionIndex, mode, cameraFeedID }: Re
Reset Region Reset Region
</button> </button>
<button <button
onClick={handleResetAll} 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" 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 Reset All

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

@@ -93,7 +93,6 @@ const VideoFeedGridPainter = () => {
const width = window.innerWidth; const width = window.innerWidth;
const aspectRatio = BACKEND_WIDTH / BACKEND_HEIGHT; const aspectRatio = BACKEND_WIDTH / BACKEND_HEIGHT;
console.log(window.innerWidth);
if (width < 768) { if (width < 768) {
const newWidth = width * 0.8; const newWidth = width * 0.8;
const newHeight = newWidth / aspectRatio; const newHeight = newWidth / aspectRatio;

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

@@ -29,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 ")} />
@@ -62,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

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

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