From b084c3016d9faaec8e1e38923061911a42dd4fc6 Mon Sep 17 00:00:00 2001 From: Toba Ojo Date: Mon, 24 Nov 2025 12:19:51 +0000 Subject: [PATCH] - improved grid painting and included resizing --- .../cameras/components/CameraGrid.tsx | 8 ++-- .../{ => CameraSettings}/CameraSettings.tsx | 24 ++++++++-- .../{ => CameraSettings}/ColourPicker.tsx | 0 .../{ => CameraSettings}/RegionSelector.tsx | 2 +- .../components/PlatePatch/PlatePatch.tsx | 7 +++ .../{ => Video}/VideoFeedGridPainter.tsx | 46 +++++++++++++++---- .../cameras/hooks/useGetvideoSnapshots.ts | 3 +- 7 files changed, 70 insertions(+), 20 deletions(-) rename src/features/cameras/components/{ => CameraSettings}/CameraSettings.tsx (61%) rename src/features/cameras/components/{ => CameraSettings}/ColourPicker.tsx (100%) rename src/features/cameras/components/{ => CameraSettings}/RegionSelector.tsx (95%) create mode 100644 src/features/cameras/components/PlatePatch/PlatePatch.tsx rename src/features/cameras/components/{ => Video}/VideoFeedGridPainter.tsx (69%) diff --git a/src/features/cameras/components/CameraGrid.tsx b/src/features/cameras/components/CameraGrid.tsx index 7cb2353..6482fa9 100644 --- a/src/features/cameras/components/CameraGrid.tsx +++ b/src/features/cameras/components/CameraGrid.tsx @@ -1,8 +1,9 @@ import { useState } from "react"; -import VideoFeedGridPainter from "./VideoFeedGridPainter"; -import CameraSettings from "./CameraSettings"; +import VideoFeedGridPainter from "./Video/VideoFeedGridPainter"; +import CameraSettings from "./CameraSettings/CameraSettings"; import type { Region } from "../../../types/types"; +import PlatePatch from "./PlatePatch/PlatePatch"; const CameraGrid = () => { const [regions, setRegions] = useState([ @@ -17,7 +18,7 @@ const CameraGrid = () => { setRegions((prev) => prev.map((r, i) => (i === index ? { ...r, brushColour: newColour } : r))); }; return ( -
+
{ isErasing={isErasing} onSelectErasing={setErasing} /> +
); }; diff --git a/src/features/cameras/components/CameraSettings.tsx b/src/features/cameras/components/CameraSettings/CameraSettings.tsx similarity index 61% rename from src/features/cameras/components/CameraSettings.tsx rename to src/features/cameras/components/CameraSettings/CameraSettings.tsx index e0669cd..88f383b 100644 --- a/src/features/cameras/components/CameraSettings.tsx +++ b/src/features/cameras/components/CameraSettings/CameraSettings.tsx @@ -1,8 +1,9 @@ -import Card from "../../../ui/Card"; +import Card from "../../../../ui/Card"; import { Tab, Tabs, TabList, TabPanel } from "react-tabs"; import "react-tabs/style/react-tabs.css"; import RegionSelector from "./RegionSelector"; -import type { Region } from "../../../types/types"; +import type { Region } from "../../../../types/types"; +import { useState } from "react"; type CameraSettingsProps = { regions: Region[]; @@ -21,12 +22,19 @@ const CameraSettings = ({ isErasing, onSelectErasing, }: CameraSettingsProps) => { + const [tabIndex, setTabIndex] = useState(0); return ( - - + + setTabIndex(index)} + > Target Detection Camera 1 + Camera 2 + Camera 3 -
Camera details
+
Camera details {tabIndex}
+
+ +
Camera details {tabIndex}
+
+ +
Camera details {tabIndex}
diff --git a/src/features/cameras/components/ColourPicker.tsx b/src/features/cameras/components/CameraSettings/ColourPicker.tsx similarity index 100% rename from src/features/cameras/components/ColourPicker.tsx rename to src/features/cameras/components/CameraSettings/ColourPicker.tsx diff --git a/src/features/cameras/components/RegionSelector.tsx b/src/features/cameras/components/CameraSettings/RegionSelector.tsx similarity index 95% rename from src/features/cameras/components/RegionSelector.tsx rename to src/features/cameras/components/CameraSettings/RegionSelector.tsx index 04d9e06..b8a1688 100644 --- a/src/features/cameras/components/RegionSelector.tsx +++ b/src/features/cameras/components/CameraSettings/RegionSelector.tsx @@ -1,5 +1,5 @@ import ColourPicker from "./ColourPicker"; -import type { Region } from "../../../types/types"; +import type { Region } from "../../../../types/types"; type RegionSelectorProps = { regions: Region[]; diff --git a/src/features/cameras/components/PlatePatch/PlatePatch.tsx b/src/features/cameras/components/PlatePatch/PlatePatch.tsx new file mode 100644 index 0000000..6a652f2 --- /dev/null +++ b/src/features/cameras/components/PlatePatch/PlatePatch.tsx @@ -0,0 +1,7 @@ +import Card from "../../../../ui/Card"; + +const PlatePatch = () => { + return PlatePatch; +}; + +export default PlatePatch; diff --git a/src/features/cameras/components/VideoFeedGridPainter.tsx b/src/features/cameras/components/Video/VideoFeedGridPainter.tsx similarity index 69% rename from src/features/cameras/components/VideoFeedGridPainter.tsx rename to src/features/cameras/components/Video/VideoFeedGridPainter.tsx index 960cdc2..ce706e1 100644 --- a/src/features/cameras/components/VideoFeedGridPainter.tsx +++ b/src/features/cameras/components/Video/VideoFeedGridPainter.tsx @@ -1,9 +1,9 @@ -import { useRef, type RefObject } from "react"; +import { useEffect, useRef, useState, type RefObject } from "react"; import { Stage, Layer, Image, Shape } from "react-konva"; import type { KonvaEventObject } from "konva/lib/Node"; -import { useCreateVideoSnapshot } from "../hooks/useGetvideoSnapshots"; -import Card from "../../../ui/Card"; -import type { Region } from "../../../types/types"; +import { useCreateVideoSnapshot } from "../../hooks/useGetvideoSnapshots"; +import type { Region } from "../../../../types/types"; +import Card from "../../../../ui/Card"; const rows = 40; const cols = 40; @@ -21,7 +21,8 @@ type PaintedCell = { }; const VideoFeedGridPainter = ({ regions, selectedRegionIndex, isErasing }: VideoFeedGridPainterProps) => { - const { latestBitmapRef } = useCreateVideoSnapshot(); + const { latestBitmapRef, isloading } = useCreateVideoSnapshot(); + const [stageSize, setStageSize] = useState({ width: 740, height: 460 }); const isDrawingRef = useRef(false); const paintedCellsRef = useRef>(new Map()); // eslint-disable-next-line @typescript-eslint/no-explicit-any @@ -35,6 +36,8 @@ const VideoFeedGridPainter = ({ regions, selectedRegionIndex, isErasing }: Video return image; }; + const image = draw(latestBitmapRef); + const paintCell = (x: number, y: number) => { const col = Math.floor(x / (size + gap)); const row = Math.floor(y / (size + gap)); @@ -83,18 +86,39 @@ const VideoFeedGridPainter = ({ regions, selectedRegionIndex, isErasing }: Video isDrawingRef.current = false; }; + useEffect(() => { + const handleResize = () => { + const width = window.innerWidth; + + const aspectRatio = 740 / 460; + const newWidth = width * 0.36; + const newHeight = newWidth / aspectRatio; + setStageSize({ width: newWidth, height: newHeight }); + }; + handleResize(); + window.addEventListener("resize", handleResize); + + return () => window.removeEventListener("resize", handleResize); + }, []); + + if (image === null || isloading) + return ( + + Loading Video feed… + + ); return ( - +
- + @@ -117,10 +141,12 @@ const VideoFeedGridPainter = ({ regions, selectedRegionIndex, isErasing }: Video ctx.fillStrokeShape(shape); }} + width={stageSize.width} + height={stageSize.height} /> - +
); }; diff --git a/src/features/cameras/hooks/useGetvideoSnapshots.ts b/src/features/cameras/hooks/useGetvideoSnapshots.ts index c9f0e66..4c9679c 100644 --- a/src/features/cameras/hooks/useGetvideoSnapshots.ts +++ b/src/features/cameras/hooks/useGetvideoSnapshots.ts @@ -6,6 +6,7 @@ export const useCreateVideoSnapshot = () => { const { videoQuery } = useGetVideoFeed(); const snapShot = videoQuery?.data; + const isloading = videoQuery.isPending; useEffect(() => { async function createBitmap() { @@ -22,5 +23,5 @@ export const useCreateVideoSnapshot = () => { createBitmap(); }, [snapShot]); - return { latestBitmapRef }; + return { latestBitmapRef, isloading }; };