From c506c395e6d88dfa19ab718bcc864b0c03a5ce57 Mon Sep 17 00:00:00 2001 From: Toba Ojo Date: Tue, 16 Sep 2025 11:07:35 +0100 Subject: [PATCH] got to a good point with sighting modal, want to do cleanup --- src/App.tsx | 21 ++-- .../CameraOverview/SnapshotContainer.tsx | 2 +- .../CameraSettings/CameraSettingFields.tsx | 11 +- src/components/HistoryList/AlertItem.tsx | 48 ++++++++ src/components/HistoryList/HistoryList.tsx | 25 ++++ src/components/PlateStack/Sighting.tsx | 19 --- src/components/PlateStack/Sightings.tsx | 21 ---- src/components/SessionForm/HitSearchCard.tsx | 16 ++- src/components/SessionForm/SessionCard.tsx | 13 +- .../BearerType/BearerTypeFields.tsx | 2 +- .../SettingForms/WiFi&Modem/ModemCard.tsx | 37 ++++-- .../SightingModal/SightingModal.tsx | 115 ++++++++++++++---- src/components/SightingsWidget/InfoBar.tsx | 32 +++++ .../SightingsWidget/SightingWidget.tsx | 78 ++++++------ src/components/UI/ModalComponent.tsx | 2 +- src/context/AlertHitContext.ts | 21 ++++ ...NPEDUserContext.tsx => NPEDUserContext.ts} | 0 ...FeedContext.tsx => SightingFeedContext.ts} | 0 src/context/providers/AlertHitProvider.tsx | 19 +++ src/context/reducers/AlertReducers.ts | 46 +++++++ src/hooks/useCameraConfig.ts | 5 +- src/hooks/useGetOverviewSnapshot.ts | 4 +- src/pages/Session.tsx | 7 ++ src/pages/SystemSettings.tsx | 2 +- src/types/types.ts | 85 ++++++++++++- 25 files changed, 490 insertions(+), 141 deletions(-) create mode 100644 src/components/HistoryList/AlertItem.tsx create mode 100644 src/components/HistoryList/HistoryList.tsx delete mode 100644 src/components/PlateStack/Sighting.tsx delete mode 100644 src/components/PlateStack/Sightings.tsx create mode 100644 src/components/SightingsWidget/InfoBar.tsx create mode 100644 src/context/AlertHitContext.ts rename src/context/{NPEDUserContext.tsx => NPEDUserContext.ts} (100%) rename src/context/{SightingFeedContext.tsx => SightingFeedContext.ts} (100%) create mode 100644 src/context/providers/AlertHitProvider.tsx create mode 100644 src/context/reducers/AlertReducers.ts diff --git a/src/App.tsx b/src/App.tsx index 6bb1323..6e6c017 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -6,19 +6,22 @@ import RearCamera from "./pages/RearCamera"; import SystemSettings from "./pages/SystemSettings"; import Session from "./pages/Session"; import { NPEDUserProvider } from "./context/providers/NPEDUserContextProvider"; +import { AlertHitProvider } from "./context/providers/AlertHitProvider"; function App() { return ( - - }> - } /> - } /> - } /> - } /> - } /> - - + + + }> + } /> + } /> + } /> + } /> + } /> + + + ); } diff --git a/src/components/CameraOverview/SnapshotContainer.tsx b/src/components/CameraOverview/SnapshotContainer.tsx index c112bcd..0b92159 100644 --- a/src/components/CameraOverview/SnapshotContainer.tsx +++ b/src/components/CameraOverview/SnapshotContainer.tsx @@ -13,7 +13,7 @@ export const SnapshotContainer = ({ const { canvasRef, isError, isPending } = useGetOverviewSnapshot(side); if (isError) return <>An error occurred; - if (isPending) return <>loading...; + if (isPending) return <>Loading...; return (
diff --git a/src/components/CameraSettings/CameraSettingFields.tsx b/src/components/CameraSettings/CameraSettingFields.tsx index 8eec8d0..c69735e 100644 --- a/src/components/CameraSettings/CameraSettingFields.tsx +++ b/src/components/CameraSettings/CameraSettingFields.tsx @@ -1,10 +1,19 @@ import { Formik, Field, Form } from "formik"; import type { + CameraConfig, CameraSettingErrorValues, CameraSettingValues, } from "../../types/types"; -const CameraSettingFields = ({ initialData, updateCameraConfig }) => { +type CameraSettingsProps = { + initialData: CameraConfig; + updateCameraConfig: (values: CameraSettingValues) => void; +}; + +const CameraSettingFields = ({ + initialData, + updateCameraConfig, +}: CameraSettingsProps) => { const initialValues: CameraSettingValues = { friendlyName: initialData?.propLEDDriverControlURI?.value, cameraAddress: "", diff --git a/src/components/HistoryList/AlertItem.tsx b/src/components/HistoryList/AlertItem.tsx new file mode 100644 index 0000000..1a531fe --- /dev/null +++ b/src/components/HistoryList/AlertItem.tsx @@ -0,0 +1,48 @@ +import type { SightingType } from "../../types/types"; +import NumberPlate from "../PlateStack/NumberPlate"; +import SightingModal from "../SightingModal/SightingModal"; +import InfoBar from "../SightingsWidget/InfoBar"; +import { useState } from "react"; + +type AlertItemProps = { + item: SightingType; +}; + +const AlertItem = ({ item }: AlertItemProps) => { + const [isModalOpen, setIsModalOpen] = useState(false); + const motionAway = (item?.motion ?? "").toUpperCase() === "AWAY"; + const isNPEDHit = item?.metadata?.npedJSON?.status_code === 404; + + const handleClick = () => { + setIsModalOpen(true); + }; + + const closeModal = () => { + setIsModalOpen(false); + }; + return ( + <> + +
+ {isNPEDHit && NPED Hit} +
+ MAKE: {item.make} + MODEL: {item.model} + COLOUR: {item.color} +
+ + +
+ + + ); +}; + +export default AlertItem; diff --git a/src/components/HistoryList/HistoryList.tsx b/src/components/HistoryList/HistoryList.tsx new file mode 100644 index 0000000..af9a40d --- /dev/null +++ b/src/components/HistoryList/HistoryList.tsx @@ -0,0 +1,25 @@ +import { useAlertHitContext } from "../../context/AlertHitContext"; +import Card from "../UI/Card"; +import CardHeader from "../UI/CardHeader"; +import AlertItem from "./AlertItem"; + +const HistoryList = () => { + const { state } = useAlertHitContext(); + console.log(state); + return ( + + +
+ {state?.alertList?.length >= 0 ? ( + state?.alertList?.map((alertItem, index) => ( + + )) + ) : ( +

No Search results

+ )} +
+
+ ); +}; + +export default HistoryList; diff --git a/src/components/PlateStack/Sighting.tsx b/src/components/PlateStack/Sighting.tsx deleted file mode 100644 index 6b235b2..0000000 --- a/src/components/PlateStack/Sighting.tsx +++ /dev/null @@ -1,19 +0,0 @@ -import NumberPlate from "./NumberPlate"; - -import type { SightingType } from "../../types/types"; - -type SightingProps = { - sighting: SightingType; -}; - -const Sighting = ({ sighting }: SightingProps) => { - return ( -
-
- -
-
- ); -}; - -export default Sighting; diff --git a/src/components/PlateStack/Sightings.tsx b/src/components/PlateStack/Sightings.tsx deleted file mode 100644 index d4db4b6..0000000 --- a/src/components/PlateStack/Sightings.tsx +++ /dev/null @@ -1,21 +0,0 @@ -import Card from "../UI/Card"; -import SightingHeader from "./SightingHeader"; -import Sighting from "./Sighting"; -import { useLatestSighting } from "../../hooks/useLatestSighting"; - -type SightingProps = { - title: string; -}; - -const Sightings = ({ title }: SightingProps) => { - const { data } = useLatestSighting(); - - return ( - - - - - ); -}; - -export default Sightings; diff --git a/src/components/SessionForm/HitSearchCard.tsx b/src/components/SessionForm/HitSearchCard.tsx index 8eab328..151c9bf 100644 --- a/src/components/SessionForm/HitSearchCard.tsx +++ b/src/components/SessionForm/HitSearchCard.tsx @@ -1,15 +1,25 @@ import Card from "../UI/Card"; import CardHeader from "../UI/CardHeader"; import FormGroup from "../SettingForms/components/FormGroup"; +import { useAlertHitContext } from "../../context/AlertHitContext"; +import { useState } from "react"; const SessionCard = () => { + const [searchTerm, setSearchTerm] = useState(""); + const { state, disptach } = useAlertHitContext(); + console.log(state); return (
- +
{ type="text" className="p-2 border border-gray-400 rounded-lg w-full max-w-xs" placeholder="Enter VRM" - //onChange={e => setSntpServer(e.target.value)} + onChange={(e) => setSearchTerm(e.target.value)} />
diff --git a/src/components/SessionForm/SessionCard.tsx b/src/components/SessionForm/SessionCard.tsx index bd6b8ce..76732c0 100644 --- a/src/components/SessionForm/SessionCard.tsx +++ b/src/components/SessionForm/SessionCard.tsx @@ -2,7 +2,6 @@ import Card from "../UI/Card"; import CardHeader from "../UI/CardHeader"; const SessionCard = () => { - return ( @@ -13,12 +12,12 @@ const SessionCard = () => { > Start Session -

Number of cars:

-

Cars without Tax:

-

Cars without MOT:

-

Cars with NPED Cat A:

-

Cars with NPED Cat B:

-

Cars with NPED Cat C:

+

Number of Vehicles:

+

Vehicles without Tax:

+

Vehicles without MOT:

+

Vehicles with NPED Cat A:

+

Vehicles with NPED Cat B:

+

Vehicles with NPED Cat C:

); diff --git a/src/components/SettingForms/BearerType/BearerTypeFields.tsx b/src/components/SettingForms/BearerType/BearerTypeFields.tsx index 5dee2d4..1985f8f 100644 --- a/src/components/SettingForms/BearerType/BearerTypeFields.tsx +++ b/src/components/SettingForms/BearerType/BearerTypeFields.tsx @@ -7,7 +7,7 @@ export const ValuesComponent = () => { }; const BearerTypeFields = () => { - const { values } = useFormikContext(); + useFormikContext(); return (
diff --git a/src/components/SettingForms/WiFi&Modem/ModemCard.tsx b/src/components/SettingForms/WiFi&Modem/ModemCard.tsx index df88abb..cad048b 100644 --- a/src/components/SettingForms/WiFi&Modem/ModemCard.tsx +++ b/src/components/SettingForms/WiFi&Modem/ModemCard.tsx @@ -10,11 +10,17 @@ const ModemCard = () => { const [authType, setAuthType] = useState("PAP"); return ( + // TODO: Add switch for Auto vs Manual settings
- + { className="p-2 border border-gray-400 rounded-lg flex-1 md:w-2/3" placeholder="Enter APN" value={apn} - onChange={e => setApn(e.target.value)} + onChange={(e) => setApn(e.target.value)} /> - + { className="p-2 border border-gray-400 rounded-lg flex-1 md:w-2/3" placeholder="Enter Username" value={username} - onChange={e => setUsername(e.target.value)} + onChange={(e) => setUsername(e.target.value)} /> - + { className="p-2 border border-gray-400 rounded-lg flex-1 md:w-2/3" placeholder="Enter Password" value={password} - onChange={e => setPassword(e.target.value)} + onChange={(e) => setPassword(e.target.value)} /> - +