Compare commits
10 Commits
main
...
feature/mo
| Author | SHA1 | Date | |
|---|---|---|---|
| 9394793669 | |||
| 3b7487da09 | |||
| a299960dfb | |||
| 4a7fb58411 | |||
| ef5f07de0a | |||
| 70083d9c60 | |||
| 6879e30b9c | |||
| c2f55898fe | |||
| 45e6a3286c | |||
| 276dcd26ed |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -22,3 +22,5 @@ dist-ssr
|
|||||||
*.njsproj
|
*.njsproj
|
||||||
*.sln
|
*.sln
|
||||||
*.sw?
|
*.sw?
|
||||||
|
|
||||||
|
.env
|
||||||
|
|||||||
3
.prettierrc
Normal file
3
.prettierrc
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"printWidth": 120
|
||||||
|
}
|
||||||
@@ -14,9 +14,15 @@
|
|||||||
"@fortawesome/free-solid-svg-icons": "^7.1.0",
|
"@fortawesome/free-solid-svg-icons": "^7.1.0",
|
||||||
"@fortawesome/react-fontawesome": "^3.1.1",
|
"@fortawesome/react-fontawesome": "^3.1.1",
|
||||||
"@tailwindcss/vite": "^4.1.18",
|
"@tailwindcss/vite": "^4.1.18",
|
||||||
|
"@tanstack/react-query": "^5.90.12",
|
||||||
"@tanstack/react-router": "^1.141.6",
|
"@tanstack/react-router": "^1.141.6",
|
||||||
|
"clsx": "^2.1.1",
|
||||||
|
"country-flag-icons": "^1.6.4",
|
||||||
|
"konva": "^10.0.12",
|
||||||
"react": "^19.2.0",
|
"react": "^19.2.0",
|
||||||
"react-dom": "^19.2.0",
|
"react-dom": "^19.2.0",
|
||||||
|
"react-konva": "^19.2.1",
|
||||||
|
"react-modal": "^3.16.3",
|
||||||
"tailwindcss": "^4.1.18"
|
"tailwindcss": "^4.1.18"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
@@ -25,6 +31,7 @@
|
|||||||
"@types/node": "^24.10.1",
|
"@types/node": "^24.10.1",
|
||||||
"@types/react": "^19.2.5",
|
"@types/react": "^19.2.5",
|
||||||
"@types/react-dom": "^19.2.3",
|
"@types/react-dom": "^19.2.3",
|
||||||
|
"@types/react-modal": "^3.16.3",
|
||||||
"@vitejs/plugin-react": "^5.1.1",
|
"@vitejs/plugin-react": "^5.1.1",
|
||||||
"eslint": "^9.39.1",
|
"eslint": "^9.39.1",
|
||||||
"eslint-plugin-react-hooks": "^7.0.1",
|
"eslint-plugin-react-hooks": "^7.0.1",
|
||||||
|
|||||||
1
src/app/config.ts
Normal file
1
src/app/config.ts
Normal file
@@ -0,0 +1 @@
|
|||||||
|
export const cambase = import.meta.env.VITE_LOCAL_CAMBASE;
|
||||||
16
src/app/context/CameraSettingsContext.ts
Normal file
16
src/app/context/CameraSettingsContext.ts
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
import { createContext, useContext } from "react";
|
||||||
|
import type { CameraSettings, CameraSettingsAction } from "../../utils/types";
|
||||||
|
|
||||||
|
type CameraSettingsContextType = {
|
||||||
|
state: CameraSettings;
|
||||||
|
dispatch: (state: CameraSettingsAction) => void;
|
||||||
|
};
|
||||||
|
export const CameraSettingsContext = createContext<CameraSettingsContextType | null>(null);
|
||||||
|
|
||||||
|
export const useCameraSettingsContext = () => {
|
||||||
|
const context = useContext(CameraSettingsContext);
|
||||||
|
if (!context) {
|
||||||
|
throw new Error("useCameraSettingsContext must be used within a CameraSettingsProvider");
|
||||||
|
}
|
||||||
|
return context;
|
||||||
|
};
|
||||||
13
src/app/providers/AppProviders.tsx
Normal file
13
src/app/providers/AppProviders.tsx
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
import { type PropsWithChildren } from "react";
|
||||||
|
import { QueryProvider } from "./QueryProvider";
|
||||||
|
import CameraSettingsProvider from "./CameraSettingsProvider";
|
||||||
|
|
||||||
|
const AppProviders = ({ children }: PropsWithChildren) => {
|
||||||
|
return (
|
||||||
|
<QueryProvider>
|
||||||
|
<CameraSettingsProvider>{children}</CameraSettingsProvider>
|
||||||
|
</QueryProvider>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default AppProviders;
|
||||||
11
src/app/providers/CameraSettingsProvider.tsx
Normal file
11
src/app/providers/CameraSettingsProvider.tsx
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
import { CameraSettingsContext } from "../context/CameraSettingsContext";
|
||||||
|
import { useReducer, type ReactNode } from "react";
|
||||||
|
import { initialState, cameraSettingsReducer } from "../reducers/cameraSettingsReducer";
|
||||||
|
|
||||||
|
const CameraSettingsProvider = ({ children }: { children: ReactNode }) => {
|
||||||
|
const [state, dispatch] = useReducer(cameraSettingsReducer, initialState);
|
||||||
|
|
||||||
|
return <CameraSettingsContext.Provider value={{ state, dispatch }}>{children}</CameraSettingsContext.Provider>;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default CameraSettingsProvider;
|
||||||
7
src/app/providers/QueryProvider.tsx
Normal file
7
src/app/providers/QueryProvider.tsx
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
import type { PropsWithChildren } from "react";
|
||||||
|
import { QueryClientProvider } from "@tanstack/react-query";
|
||||||
|
import { queryClient } from "../queryClient";
|
||||||
|
|
||||||
|
export function QueryProvider({ children }: PropsWithChildren) {
|
||||||
|
return <QueryClientProvider client={queryClient}>{children}</QueryClientProvider>;
|
||||||
|
}
|
||||||
10
src/app/queryClient.ts
Normal file
10
src/app/queryClient.ts
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
import { QueryClient } from "@tanstack/react-query";
|
||||||
|
|
||||||
|
export const queryClient = new QueryClient({
|
||||||
|
defaultOptions: {
|
||||||
|
queries: {
|
||||||
|
staleTime: 60_000,
|
||||||
|
refetchOnWindowFocus: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
23
src/app/reducers/cameraSettingsReducer.ts
Normal file
23
src/app/reducers/cameraSettingsReducer.ts
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
import type { CameraSettings, CameraSettingsAction } from "../../utils/types";
|
||||||
|
|
||||||
|
export const initialState: CameraSettings = {
|
||||||
|
mode: 0,
|
||||||
|
imageSize: { width: 1280, height: 960 },
|
||||||
|
};
|
||||||
|
|
||||||
|
export const cameraSettingsReducer = (state: CameraSettings, action: CameraSettingsAction) => {
|
||||||
|
switch (action.type) {
|
||||||
|
case "SET_MODE":
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
mode: action.payload,
|
||||||
|
};
|
||||||
|
case "SET_IMAGE_SIZE":
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
imageSize: action.payload,
|
||||||
|
};
|
||||||
|
default:
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
};
|
||||||
21
src/components/CardHeader.tsx
Normal file
21
src/components/CardHeader.tsx
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
import clsx from "clsx";
|
||||||
|
|
||||||
|
type CardHeaderProps = {
|
||||||
|
title: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
const CardHeader = ({ title }: CardHeaderProps) => {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
className={clsx(
|
||||||
|
"w-full border-b border-gray-600 flex flex-row items-center space-x-2 mb-6 relative justify-between",
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<div className="flex flex-row items-center w-full justify-between">
|
||||||
|
<h2 className="flex flex-row text-xl items-center">{title}</h2>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default CardHeader;
|
||||||
22
src/components/ui/Card.tsx
Normal file
22
src/components/ui/Card.tsx
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
import React from "react";
|
||||||
|
import clsx from "clsx";
|
||||||
|
|
||||||
|
type CardProps = {
|
||||||
|
children: React.ReactNode;
|
||||||
|
className?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
const Card = ({ children, className }: CardProps) => {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
className={clsx(
|
||||||
|
"bg-[#253445] rounded-lg mt-4 shadow-2xl overflow-x-hidden md:row-span-1 px-2 border border-gray-600 ",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Card;
|
||||||
38
src/components/ui/ModalComponent.tsx
Normal file
38
src/components/ui/ModalComponent.tsx
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
import Modal from "react-modal";
|
||||||
|
|
||||||
|
type ModalComponentProps = {
|
||||||
|
isModalOpen: boolean;
|
||||||
|
children: React.ReactNode;
|
||||||
|
close: () => void;
|
||||||
|
};
|
||||||
|
const ModalComponent = ({ isModalOpen, children, close }: ModalComponentProps) => {
|
||||||
|
return (
|
||||||
|
<Modal
|
||||||
|
isOpen={isModalOpen}
|
||||||
|
onRequestClose={close}
|
||||||
|
className="bg-[#1e2a38] p-6 rounded-lg shadow-lg w-[95%] mt-[2%] md:w-[60%] 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"
|
||||||
|
closeTimeoutMS={200}
|
||||||
|
style={{
|
||||||
|
overlay: {
|
||||||
|
transition: "opacity 200ms ease-in-out",
|
||||||
|
},
|
||||||
|
content: {
|
||||||
|
transition: "all 200ms ease-in-out",
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div className="flex justify-end">
|
||||||
|
<button
|
||||||
|
onClick={close}
|
||||||
|
className="bg-gray-700 hover:bg-gray-600 text-white font-bold py-2 px-4 rounded-lg mb-4 hover:cursor-pointer"
|
||||||
|
>
|
||||||
|
Close
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
{children}
|
||||||
|
</Modal>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default ModalComponent;
|
||||||
25
src/features/dashboard/Dashboard.tsx
Normal file
25
src/features/dashboard/Dashboard.tsx
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
import PlateRead from "./components/plateRead/PlateRead";
|
||||||
|
import SightingStack from "./components/sightingStack/SightingStack";
|
||||||
|
import VideoFeed from "./components/videoFeed/VideoFeed";
|
||||||
|
import { useSightingList } from "./hooks/useSightingList";
|
||||||
|
import { useCameraSettingsContext } from "../../app/context/CameraSettingsContext";
|
||||||
|
|
||||||
|
const Dashboard = () => {
|
||||||
|
const { sightingList, isLoading } = useSightingList();
|
||||||
|
const { state: cameraSettings } = useCameraSettingsContext();
|
||||||
|
const size = cameraSettings.imageSize;
|
||||||
|
|
||||||
|
const mostRecent = sightingList[0];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="grid gird-cols-1 md:grid-cols-2 gap-2 md:gap-5">
|
||||||
|
<div>
|
||||||
|
<VideoFeed mostRecentSighting={mostRecent} isLoading={isLoading} size={size} />
|
||||||
|
<PlateRead sighting={mostRecent} />
|
||||||
|
</div>
|
||||||
|
<SightingStack sightings={sightingList} />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Dashboard;
|
||||||
57
src/features/dashboard/components/platePatch/NumberPlate.tsx
Normal file
57
src/features/dashboard/components/platePatch/NumberPlate.tsx
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
import { GB } from "country-flag-icons/react/3x2";
|
||||||
|
import { formatNumberPlate } from "../../../../utils/utils";
|
||||||
|
|
||||||
|
type NumberPlateProps = {
|
||||||
|
vrm?: string | undefined;
|
||||||
|
motion?: boolean;
|
||||||
|
size?: "xs" | "sm" | "md" | "lg";
|
||||||
|
};
|
||||||
|
|
||||||
|
const NumberPlate = ({ vrm, motion, size }: NumberPlateProps) => {
|
||||||
|
let options = {
|
||||||
|
plateWidth: "w-[14rem]",
|
||||||
|
textSize: "text-2xl",
|
||||||
|
borderWidth: "border-6",
|
||||||
|
};
|
||||||
|
|
||||||
|
switch (size) {
|
||||||
|
case "xs":
|
||||||
|
options = {
|
||||||
|
plateWidth: "w-[8rem]",
|
||||||
|
textSize: "text-md",
|
||||||
|
borderWidth: "border-4",
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
case "sm":
|
||||||
|
options = {
|
||||||
|
plateWidth: "w-[10rem]",
|
||||||
|
textSize: "text-lg",
|
||||||
|
borderWidth: "border-4",
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
case "lg":
|
||||||
|
options = {
|
||||||
|
plateWidth: "w-[16rem]",
|
||||||
|
textSize: "text-3xl",
|
||||||
|
borderWidth: "border-6",
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
className={`relative ${options.plateWidth} ${options.borderWidth} border-black rounded-xl text-nowrap
|
||||||
|
text-black px-6 py-2 text-monospace flex items-center justify-center
|
||||||
|
${motion ? "bg-yellow-400" : "bg-white"}`}
|
||||||
|
>
|
||||||
|
<div>
|
||||||
|
<div className="absolute inset-y-0 left-0 bg-blue-600 w-8 flex flex-col">
|
||||||
|
<GB />
|
||||||
|
</div>
|
||||||
|
<p className={`pl-4 font-extrabold ${options.textSize} text-right`}>{vrm && formatNumberPlate(vrm)}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default NumberPlate;
|
||||||
55
src/features/dashboard/components/plateRead/PlateRead.tsx
Normal file
55
src/features/dashboard/components/plateRead/PlateRead.tsx
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
import type { SightingType } from "../../../../utils/types";
|
||||||
|
import Card from "../../../../components/ui/Card";
|
||||||
|
import CardHeader from "../../../../components/CardHeader";
|
||||||
|
|
||||||
|
type PlateReadProps = {
|
||||||
|
sighting: SightingType;
|
||||||
|
};
|
||||||
|
|
||||||
|
const PlateRead = ({ sighting }: PlateReadProps) => {
|
||||||
|
const vrm = sighting?.vrm;
|
||||||
|
const region = sighting?.laneID;
|
||||||
|
const timestamp = sighting?.timeStamp;
|
||||||
|
const seenCount = sighting?.seenCount;
|
||||||
|
const radarSpeed = sighting?.radarSpeed;
|
||||||
|
const motion = sighting?.motion;
|
||||||
|
const countryCode = sighting?.countryCode;
|
||||||
|
const plateColorUrl = sighting?.plateUrlColour;
|
||||||
|
|
||||||
|
if (!sighting) return <div>No sighting data available.</div>;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Card className="p-4 w-full">
|
||||||
|
<CardHeader title="Plate Read" />
|
||||||
|
<dl className="grid grid-cols-[auto_1fr] gap-x-4 gap-y-2 text-sm">
|
||||||
|
<dt className="font-semibold text-gray-200">VRM:</dt>
|
||||||
|
<dd>{vrm}</dd>
|
||||||
|
<dt className="font-semibold text-gray-200">Region:</dt>
|
||||||
|
<dd>{region}</dd>
|
||||||
|
<dt className="font-semibold text-gray-200">Timestamp:</dt>
|
||||||
|
<dd>{timestamp}</dd>
|
||||||
|
|
||||||
|
<dt className="font-semibold text-gray-200">Seen Count:</dt>
|
||||||
|
<dd>{seenCount}</dd>
|
||||||
|
|
||||||
|
<dt className="font-semibold text-gray-200">Radar Speed:</dt>
|
||||||
|
<dd>{radarSpeed} mph</dd>
|
||||||
|
|
||||||
|
<dt className="font-semibold text-gray-200">Motion:</dt>
|
||||||
|
<dd>{motion}</dd>
|
||||||
|
|
||||||
|
<dt className="font-semibold text-gray-200">Country Code:</dt>
|
||||||
|
<dd>{countryCode}</dd>
|
||||||
|
|
||||||
|
<dt className="font-semibold text-gray-200">Plate Image:</dt>
|
||||||
|
<dd>
|
||||||
|
<a href={plateColorUrl} target="_blank" rel="noopener noreferrer" className="text-blue-600 hover:underline">
|
||||||
|
View Image
|
||||||
|
</a>
|
||||||
|
</dd>
|
||||||
|
</dl>
|
||||||
|
</Card>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default PlateRead;
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
import type { SightingType } from "../../../../utils/types";
|
||||||
|
import { timeAgo } from "../../../../utils/utils";
|
||||||
|
import NumberPlate from "../platePatch/NumberPlate";
|
||||||
|
|
||||||
|
type SightingItemProps = {
|
||||||
|
sighting: SightingType;
|
||||||
|
onOpenModal: () => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
const SightingItem = ({ sighting, onOpenModal }: SightingItemProps) => {
|
||||||
|
const motion = sighting.motion.toLowerCase() === "away" ? true : false;
|
||||||
|
const timeStamp = timeAgo(sighting.timeStampMillis);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div
|
||||||
|
className="flex flex-row items-center border p-2 mb-2 rounded-lg border-gray-500 justify-between hover:bg-[#233241] hover:cursor-pointer"
|
||||||
|
onClick={onOpenModal}
|
||||||
|
>
|
||||||
|
<div>
|
||||||
|
<div>
|
||||||
|
<span className="font-light border bg-blue-400 text-blue-800 px-2 rounded">{timeStamp}</span>
|
||||||
|
</div>
|
||||||
|
<div className="text-xl">
|
||||||
|
<span className="font-semibold text-gray-200">{sighting.vrm}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{window.innerWidth > 768 ? (
|
||||||
|
<NumberPlate vrm={sighting.vrm} motion={motion} size="md" />
|
||||||
|
) : (
|
||||||
|
<NumberPlate vrm={sighting.vrm} motion={motion} size="sm" />
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default SightingItem;
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
import { useState } from "react";
|
||||||
|
import CardHeader from "../../../../components/CardHeader";
|
||||||
|
import Card from "../../../../components/ui/Card";
|
||||||
|
import type { SightingType } from "../../../../utils/types";
|
||||||
|
import SightingItem from "./SightingItem";
|
||||||
|
import SightingItemModal from "./sightingItemModal/SightingItemModal";
|
||||||
|
|
||||||
|
type SightingStackProps = {
|
||||||
|
sightings: SightingType[];
|
||||||
|
};
|
||||||
|
const SightingStack = ({ sightings }: SightingStackProps) => {
|
||||||
|
const [isSightingModalOpen, setIsSightingModalOpen] = useState(false);
|
||||||
|
const [currentSighting, setCurrentSighting] = useState<SightingType | null>(null);
|
||||||
|
const handleOpenModal = (sighting: SightingType | null) => {
|
||||||
|
if (!sighting) return;
|
||||||
|
setCurrentSighting(sighting);
|
||||||
|
setIsSightingModalOpen(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Card className="p-4 w-full h-full">
|
||||||
|
<CardHeader title="Live Sightings" />
|
||||||
|
<div className="md:h-[65%]">
|
||||||
|
{sightings.map((sighting) => (
|
||||||
|
<SightingItem key={sighting.ref} sighting={sighting} onOpenModal={() => handleOpenModal(sighting)} />
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</Card>
|
||||||
|
<SightingItemModal
|
||||||
|
isOpen={isSightingModalOpen}
|
||||||
|
close={() => setIsSightingModalOpen(false)}
|
||||||
|
sighting={currentSighting}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default SightingStack;
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
import ModalComponent from "../../../../../components/ui/ModalComponent";
|
||||||
|
import type { SightingType } from "../../../../../utils/types";
|
||||||
|
import SightingModalContent from "./SightingModalContent";
|
||||||
|
|
||||||
|
type SightingItemModalProps = {
|
||||||
|
isOpen: boolean;
|
||||||
|
close: () => void;
|
||||||
|
sighting: SightingType | null;
|
||||||
|
};
|
||||||
|
const SightingItemModal = ({ isOpen, close, sighting }: SightingItemModalProps) => {
|
||||||
|
return (
|
||||||
|
<ModalComponent isModalOpen={isOpen} close={close}>
|
||||||
|
<SightingModalContent sighting={sighting} />
|
||||||
|
</ModalComponent>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default SightingItemModal;
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
import { useCameraSettingsContext } from "../../../../../app/context/CameraSettingsContext";
|
||||||
|
import type { SightingType } from "../../../../../utils/types";
|
||||||
|
import { timeAgo } from "../../../../../utils/utils";
|
||||||
|
import NumberPlate from "../../platePatch/NumberPlate";
|
||||||
|
import VideoFeed from "../../videoFeed/VideoFeed";
|
||||||
|
|
||||||
|
type SightingModalContentProps = {
|
||||||
|
sighting: SightingType | null;
|
||||||
|
};
|
||||||
|
|
||||||
|
const SightingModalContent = ({ sighting }: SightingModalContentProps) => {
|
||||||
|
const { state: cameraSettings } = useCameraSettingsContext();
|
||||||
|
const size = cameraSettings.imageSize;
|
||||||
|
const modalImageSize = { width: size.width / 1.5, height: size.height / 1.5 };
|
||||||
|
const timeStamp = timeAgo(sighting?.timeStampMillis ?? null);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
{sighting ? (
|
||||||
|
<>
|
||||||
|
<div className="flex flex-row items-center justify-between mb-6 border-b border-gray-600">
|
||||||
|
<h2 className="text-2xl font-bold">Sighting Details</h2>
|
||||||
|
<NumberPlate vrm={sighting.vrm} motion={sighting.motion.toLowerCase() === "away"} size="md" />
|
||||||
|
</div>
|
||||||
|
<div className="grid grid-cols-1 lg:grid-cols-3 gap-6">
|
||||||
|
<div className="lg:col-span-2">
|
||||||
|
<VideoFeed mostRecentSighting={sighting} isLoading={false} size={modalImageSize} isModal={true} />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="space-y-4 border p-4 rounded-lg border-gray-600">
|
||||||
|
<div>
|
||||||
|
<p className="text-md text-gray-300">VRM</p>
|
||||||
|
<p className="text-lg font-semibold">{sighting.vrm}</p>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<p className="text-md text-gray-300">Seen</p>
|
||||||
|
<p className="text-md">{timeStamp}</p>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<p className="text-md text-gray-300">Timestamp</p>
|
||||||
|
<p className="text-md">{new Date(sighting.timeStampMillis).toLocaleString()}</p>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<p className="text-md text-gray-300">Motion</p>
|
||||||
|
<p className="text-lg font-semibold">{sighting.motion}</p>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<p className="text-md text-gray-300">Radar Speed</p>
|
||||||
|
<p className="text-lg font-semibold">{sighting.radarSpeed} mph</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<p className="text-gray-300">No sighting data available.</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default SightingModalContent;
|
||||||
42
src/features/dashboard/components/videoFeed/VideoButton.tsx
Normal file
42
src/features/dashboard/components/videoFeed/VideoButton.tsx
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
import { useState } from "react";
|
||||||
|
import { Text, Group, Rect } from "react-konva";
|
||||||
|
|
||||||
|
type VideoButtonProps = {
|
||||||
|
x?: number;
|
||||||
|
y?: number;
|
||||||
|
onClick?: () => void;
|
||||||
|
text?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
const VideoButton = ({ x, y, onClick, text }: VideoButtonProps) => {
|
||||||
|
const [isHovered, setIsHovered] = useState(false);
|
||||||
|
return (
|
||||||
|
<Group
|
||||||
|
x={x}
|
||||||
|
y={y}
|
||||||
|
onClick={onClick}
|
||||||
|
onMouseEnter={(e) => {
|
||||||
|
setIsHovered(true);
|
||||||
|
const container = e.target.getStage()?.container();
|
||||||
|
if (container) container.style.cursor = "pointer";
|
||||||
|
}}
|
||||||
|
onMouseLeave={(e) => {
|
||||||
|
setIsHovered(false);
|
||||||
|
const container = e.target.getStage()?.container();
|
||||||
|
if (container) container.style.cursor = "default";
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Rect
|
||||||
|
width={100}
|
||||||
|
height={35}
|
||||||
|
fill={isHovered ? "#2563eb" : "#3b82f6"}
|
||||||
|
cornerRadius={8}
|
||||||
|
shadowBlur={isHovered ? 10 : 5}
|
||||||
|
shadowOpacity={0.3}
|
||||||
|
/>
|
||||||
|
<Text text={text} fontSize={14} fill="white" width={100} height={35} align="center" verticalAlign="middle" />
|
||||||
|
</Group>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default VideoButton;
|
||||||
121
src/features/dashboard/components/videoFeed/VideoFeed.tsx
Normal file
121
src/features/dashboard/components/videoFeed/VideoFeed.tsx
Normal file
@@ -0,0 +1,121 @@
|
|||||||
|
import { Stage, Layer, Image, Rect, Text } from "react-konva";
|
||||||
|
import type { SightingType } from "../../../../utils/types";
|
||||||
|
import { useCreateVideoSnapshot } from "../../hooks/useCreateVideoSnapshot";
|
||||||
|
import { useEffect, useState } from "react";
|
||||||
|
import { useCameraSettingsContext } from "../../../../app/context/CameraSettingsContext";
|
||||||
|
|
||||||
|
type VideoFeedProps = {
|
||||||
|
mostRecentSighting: SightingType;
|
||||||
|
isLoading: boolean;
|
||||||
|
size: { width: number; height: number };
|
||||||
|
|
||||||
|
modeSetting?: number;
|
||||||
|
isModal?: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
const VideoFeed = ({ mostRecentSighting, isLoading, size, modeSetting, isModal = false }: VideoFeedProps) => {
|
||||||
|
const { state: cameraSettings, dispatch } = useCameraSettingsContext();
|
||||||
|
const contextMode = cameraSettings.mode;
|
||||||
|
const [localMode, setLocalMode] = useState(0);
|
||||||
|
const mode = isModal ? localMode : contextMode;
|
||||||
|
const { image, plateRect, plateTrack } = useCreateVideoSnapshot(mostRecentSighting);
|
||||||
|
|
||||||
|
const handleModeChange = (newMode: number) => {
|
||||||
|
if (modeSetting) return;
|
||||||
|
|
||||||
|
const nextMode = newMode > 2 ? 0 : newMode;
|
||||||
|
|
||||||
|
if (isModal) {
|
||||||
|
setLocalMode(nextMode);
|
||||||
|
} else {
|
||||||
|
dispatch({ type: "SET_MODE", payload: nextMode });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const updateSize = () => {
|
||||||
|
const width = window.innerWidth * 0.48;
|
||||||
|
const height = (width * 2) / 3;
|
||||||
|
dispatch({ type: "SET_IMAGE_SIZE", payload: { width, height } });
|
||||||
|
};
|
||||||
|
updateSize();
|
||||||
|
window.addEventListener("resize", updateSize);
|
||||||
|
return () => window.removeEventListener("resize", updateSize);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
if (isLoading) return <>Loading...</>;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="w-[70%] mt-[2%]">
|
||||||
|
<Stage width={size.width} height={size.height} onClick={() => handleModeChange(mode + 1)}>
|
||||||
|
<Layer>
|
||||||
|
{image && (
|
||||||
|
<Image
|
||||||
|
image={image}
|
||||||
|
height={size.height}
|
||||||
|
width={size.width}
|
||||||
|
onMouseEnter={(e) => {
|
||||||
|
const container = e.target.getStage()?.container();
|
||||||
|
if (container) container.style.cursor = "pointer";
|
||||||
|
}}
|
||||||
|
onMouseLeave={(e) => {
|
||||||
|
const container = e.target.getStage()?.container();
|
||||||
|
if (container) container.style.cursor = "default";
|
||||||
|
}}
|
||||||
|
cornerRadius={10}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</Layer>
|
||||||
|
{plateRect && mode === 1 && (
|
||||||
|
<Layer>
|
||||||
|
<Rect
|
||||||
|
x={plateRect?.[0] * size.width}
|
||||||
|
y={plateRect?.[1] * size.height}
|
||||||
|
width={plateRect?.[2] * size.width}
|
||||||
|
height={plateRect?.[3] * size.height}
|
||||||
|
stroke="blue"
|
||||||
|
strokeWidth={4}
|
||||||
|
cornerRadius={5}
|
||||||
|
/>
|
||||||
|
</Layer>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{plateTrack && mode === 2 && (
|
||||||
|
<Layer>
|
||||||
|
{plateTrack.map((rect, index) => (
|
||||||
|
<Rect
|
||||||
|
key={index}
|
||||||
|
x={rect[0] * size.width}
|
||||||
|
y={rect[1] * size.height}
|
||||||
|
width={rect[2] * size.width}
|
||||||
|
height={rect[3] * size.height}
|
||||||
|
stroke="red"
|
||||||
|
strokeWidth={2}
|
||||||
|
cornerRadius={5}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</Layer>
|
||||||
|
)}
|
||||||
|
<Layer>
|
||||||
|
<Rect
|
||||||
|
x={5}
|
||||||
|
y={0.955 * size.height}
|
||||||
|
width={size.width * 0.35}
|
||||||
|
height={30}
|
||||||
|
fill="rgba(255, 255, 255, 0.45)"
|
||||||
|
cornerRadius={5}
|
||||||
|
/>
|
||||||
|
<Text
|
||||||
|
text={`Overlay Mode: ${mode === 0 ? "None" : mode === 1 ? "Plate Highlight" : "Plate Track"}`}
|
||||||
|
x={10}
|
||||||
|
y={0.96 * size.height}
|
||||||
|
fontSize={16}
|
||||||
|
fill="#000000"
|
||||||
|
/>
|
||||||
|
</Layer>
|
||||||
|
</Stage>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default VideoFeed;
|
||||||
27
src/features/dashboard/hooks/useCreateVideoSnapshot.ts
Normal file
27
src/features/dashboard/hooks/useCreateVideoSnapshot.ts
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
import { useRef } from "react";
|
||||||
|
import type { SightingType } from "../../../utils/types";
|
||||||
|
|
||||||
|
export const useCreateVideoSnapshot = (mostRecentSighting: SightingType | null) => {
|
||||||
|
const latestBitMapRef = useRef<ImageBitmap | null>(null);
|
||||||
|
if (!mostRecentSighting) {
|
||||||
|
return {
|
||||||
|
snapshotUrl: null,
|
||||||
|
latestBitMapRef: null,
|
||||||
|
image: null,
|
||||||
|
plateRect: null,
|
||||||
|
plateTrack: null,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const snapshotUrl = mostRecentSighting?.overviewUrl;
|
||||||
|
|
||||||
|
const image = new Image();
|
||||||
|
|
||||||
|
image.src = snapshotUrl;
|
||||||
|
|
||||||
|
const plateRect = mostRecentSighting?.overviewPlateRect;
|
||||||
|
|
||||||
|
const plateTrack = mostRecentSighting?.plateTrack;
|
||||||
|
|
||||||
|
return { snapshotUrl, latestBitMapRef, image, plateRect, plateTrack };
|
||||||
|
};
|
||||||
27
src/features/dashboard/hooks/useSightingList.ts
Normal file
27
src/features/dashboard/hooks/useSightingList.ts
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
import { useEffect, useRef, useState } from "react";
|
||||||
|
import { useVideoFeed } from "./useVideoFeed";
|
||||||
|
import type { SightingType } from "../../../utils/types";
|
||||||
|
|
||||||
|
export const useSightingList = () => {
|
||||||
|
const [sightingList, setSightingList] = useState<SightingType[]>([]);
|
||||||
|
const { videoFeedQuery } = useVideoFeed();
|
||||||
|
const latestSighting = videoFeedQuery?.data;
|
||||||
|
const lastProcessedRef = useRef<number>(-1);
|
||||||
|
const isLoading = videoFeedQuery?.isPending;
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!latestSighting || latestSighting.ref === undefined || latestSighting.ref === -1) return;
|
||||||
|
|
||||||
|
if (latestSighting.ref !== lastProcessedRef.current) {
|
||||||
|
lastProcessedRef.current = latestSighting.ref;
|
||||||
|
|
||||||
|
// eslint-disable-next-line react-hooks/set-state-in-effect
|
||||||
|
setSightingList((prevList) => {
|
||||||
|
if (prevList[0]?.ref === latestSighting.ref) return prevList;
|
||||||
|
const dedupPrev = prevList.filter((s) => s.ref !== latestSighting.ref);
|
||||||
|
return [latestSighting, ...dedupPrev].slice(0, 10);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}, [latestSighting, latestSighting?.ref]);
|
||||||
|
return { sightingList, isLoading };
|
||||||
|
};
|
||||||
32
src/features/dashboard/hooks/useVideoFeed.ts
Normal file
32
src/features/dashboard/hooks/useVideoFeed.ts
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
import { useQuery } from "@tanstack/react-query";
|
||||||
|
import { cambase } from "../../../app/config";
|
||||||
|
import { useEffect, useRef } from "react";
|
||||||
|
|
||||||
|
const fetchVideoFeed = async (refId: number) => {
|
||||||
|
const response = await fetch(`${cambase}/mergedHistory/sightingSummary?mostRecentRef=${refId}`);
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error("Network response was not ok");
|
||||||
|
}
|
||||||
|
return response.json();
|
||||||
|
};
|
||||||
|
|
||||||
|
export const useVideoFeed = () => {
|
||||||
|
const currentRefId = useRef<number>(-1);
|
||||||
|
|
||||||
|
const videoFeedQuery = useQuery({
|
||||||
|
queryKey: ["videoFeed"],
|
||||||
|
queryFn: () => fetchVideoFeed(currentRefId.current),
|
||||||
|
refetchInterval: 400,
|
||||||
|
refetchOnWindowFocus: false,
|
||||||
|
retry: false,
|
||||||
|
staleTime: 0,
|
||||||
|
});
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (videoFeedQuery.data?.ref !== -1) {
|
||||||
|
currentRefId.current = videoFeedQuery?.data?.ref;
|
||||||
|
}
|
||||||
|
}, [videoFeedQuery.data]);
|
||||||
|
|
||||||
|
return { videoFeedQuery };
|
||||||
|
};
|
||||||
10
src/main.tsx
10
src/main.tsx
@@ -3,12 +3,14 @@ import { createRoot } from "react-dom/client";
|
|||||||
import "./index.css";
|
import "./index.css";
|
||||||
import { RouterProvider, createRouter } from "@tanstack/react-router";
|
import { RouterProvider, createRouter } from "@tanstack/react-router";
|
||||||
import { routeTree } from "./routeTree.gen.ts";
|
import { routeTree } from "./routeTree.gen.ts";
|
||||||
|
import AppProviders from "./app/providers/AppProviders.tsx";
|
||||||
|
import Modal from "react-modal";
|
||||||
|
|
||||||
const router = createRouter({
|
const router = createRouter({
|
||||||
routeTree,
|
routeTree,
|
||||||
basepath: "/aiq-lite",
|
basepath: "/aiq-lite",
|
||||||
});
|
});
|
||||||
|
Modal.setAppElement("#root");
|
||||||
declare module "@tanstack/react-router" {
|
declare module "@tanstack/react-router" {
|
||||||
interface Register {
|
interface Register {
|
||||||
router: typeof router;
|
router: typeof router;
|
||||||
@@ -17,6 +19,8 @@ declare module "@tanstack/react-router" {
|
|||||||
|
|
||||||
createRoot(document.getElementById("root")!).render(
|
createRoot(document.getElementById("root")!).render(
|
||||||
<StrictMode>
|
<StrictMode>
|
||||||
<RouterProvider router={router} />
|
<AppProviders>
|
||||||
</StrictMode>
|
<RouterProvider router={router} />
|
||||||
|
</AppProviders>
|
||||||
|
</StrictMode>,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { createRootRoute, Outlet } from "@tanstack/react-router";
|
import { createRootRoute, Outlet } from "@tanstack/react-router";
|
||||||
import Header from "../ui/Header";
|
import Header from "../components/ui/Header";
|
||||||
import Footer from "../ui/Footer";
|
import Footer from "../components/ui/Footer";
|
||||||
|
|
||||||
const RootLayout = () => {
|
const RootLayout = () => {
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
import { createFileRoute } from "@tanstack/react-router";
|
import { createFileRoute } from "@tanstack/react-router";
|
||||||
|
import Dashboard from "../features/dashboard/Dashboard";
|
||||||
|
|
||||||
export const Route = createFileRoute("/")({
|
export const Route = createFileRoute("/")({
|
||||||
component: RouteComponent,
|
component: RouteComponent,
|
||||||
});
|
});
|
||||||
|
|
||||||
function RouteComponent() {
|
function RouteComponent() {
|
||||||
return <div className="">Hello "/"!</div>;
|
return <Dashboard />;
|
||||||
}
|
}
|
||||||
|
|||||||
67
src/utils/types.ts
Normal file
67
src/utils/types.ts
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
export type SightingType = {
|
||||||
|
ref: number;
|
||||||
|
SaFID: string;
|
||||||
|
overviewUrl: string;
|
||||||
|
plateUrlInfrared: string;
|
||||||
|
plateUrlColour: string;
|
||||||
|
vrm: string;
|
||||||
|
vrmSecondary: string;
|
||||||
|
countryCode: string;
|
||||||
|
timeStamp: string;
|
||||||
|
detailsUrl: string;
|
||||||
|
overviewPlateRect?: [number, number, number, number];
|
||||||
|
plateTrack?: [number, number, number, number][];
|
||||||
|
make: string;
|
||||||
|
model: string;
|
||||||
|
color: string;
|
||||||
|
category: string;
|
||||||
|
charHeight: string;
|
||||||
|
seenCount: string;
|
||||||
|
timeStampMillis: number;
|
||||||
|
motion: string;
|
||||||
|
debug: string;
|
||||||
|
srcCam: number;
|
||||||
|
locationName: string;
|
||||||
|
laneID: string;
|
||||||
|
plateSize: string;
|
||||||
|
overviewSize: string;
|
||||||
|
radarSpeed: string;
|
||||||
|
trackSpeed: string;
|
||||||
|
metadata?: Metadata;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type Metadata = {
|
||||||
|
npedJSON: NpedJSON;
|
||||||
|
"hotlist-matches": HotlistMatches;
|
||||||
|
hotlistMatches: HotlistMatches;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type HotlistMatches = {
|
||||||
|
Hotlist0: boolean;
|
||||||
|
Hotlist1: boolean;
|
||||||
|
Hotlist2: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type NpedJSON = {
|
||||||
|
status_code: number;
|
||||||
|
reason_phrase: string;
|
||||||
|
"NPED CATEGORY": "A" | "B" | "C" | "D";
|
||||||
|
"MOT STATUS": boolean;
|
||||||
|
"TAX STATUS": boolean;
|
||||||
|
vrm: string;
|
||||||
|
"INSURANCE STATUS": string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type CameraSettings = {
|
||||||
|
mode: number;
|
||||||
|
imageSize: { width: number; height: number };
|
||||||
|
};
|
||||||
|
export type CameraSettingsAction =
|
||||||
|
| {
|
||||||
|
type: "SET_MODE";
|
||||||
|
payload: number;
|
||||||
|
}
|
||||||
|
| {
|
||||||
|
type: "SET_IMAGE_SIZE";
|
||||||
|
payload: { width: number; height: number };
|
||||||
|
};
|
||||||
24
src/utils/utils.ts
Normal file
24
src/utils/utils.ts
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
export const formatNumberPlate = (plate: string) => {
|
||||||
|
const splittedPlate = plate?.split("");
|
||||||
|
splittedPlate?.splice(4, 0, " ");
|
||||||
|
const formattedPlate = splittedPlate?.join("");
|
||||||
|
return formattedPlate;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const timeAgo = (timestampmili: number | null) => {
|
||||||
|
if (timestampmili === null) return "unknown";
|
||||||
|
const diffMs = Date.now() - new Date(timestampmili).getTime();
|
||||||
|
const diffMins = Math.floor(diffMs / 60000);
|
||||||
|
if (diffMins < 60) {
|
||||||
|
if (diffMins < 1) {
|
||||||
|
return "just now";
|
||||||
|
}
|
||||||
|
return `${diffMins === 1 ? "1 minute" : diffMins + " minutes"} ago`;
|
||||||
|
} else {
|
||||||
|
const diffHours = Math.floor(diffMins / 60);
|
||||||
|
if (diffHours < 1) {
|
||||||
|
return "just now";
|
||||||
|
}
|
||||||
|
return `${diffHours === 1 ? "1 hour" : diffHours + " hours"} ago`;
|
||||||
|
}
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user