develop #16
@@ -5,7 +5,7 @@ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
|||||||
import { faEye, faEyeSlash } from "@fortawesome/free-regular-svg-icons";
|
import { faEye, faEyeSlash } from "@fortawesome/free-regular-svg-icons";
|
||||||
import CardHeader from "../UI/CardHeader";
|
import CardHeader from "../UI/CardHeader";
|
||||||
import { useCameraMode, useCameraZoom } from "../../hooks/useCameraZoom";
|
import { useCameraMode, useCameraZoom } from "../../hooks/useCameraZoom";
|
||||||
import { parseRTSPUrl, reverseZoomMapping, zoomMapping } from "../../utils/utils";
|
import { capitalize, parseRTSPUrl, reverseZoomMapping, zoomMapping } from "../../utils/utils";
|
||||||
|
|
||||||
type CameraSettingsProps = {
|
type CameraSettingsProps = {
|
||||||
initialData: CameraConfig;
|
initialData: CameraConfig;
|
||||||
@@ -181,9 +181,9 @@ const CameraSettingFields = ({
|
|||||||
<div
|
<div
|
||||||
role="radiogroup"
|
role="radiogroup"
|
||||||
aria-label="Camera mode"
|
aria-label="Camera mode"
|
||||||
className="mx-auto grid grid-cols-2 place-items-center gap-3"
|
className="mx-auto grid grid-cols-3 place-items-center gap-3"
|
||||||
>
|
>
|
||||||
{["day", "night"].map((el) => (
|
{["day", "night", "auto"].map((el) => (
|
||||||
<div key={el} className="my-3">
|
<div key={el} className="my-3">
|
||||||
<Field
|
<Field
|
||||||
type="radio"
|
type="radio"
|
||||||
@@ -205,7 +205,7 @@ const CameraSettingFields = ({
|
|||||||
peer-checked:text-blue-600 peer-checked:bg-gray-100
|
peer-checked:text-blue-600 peer-checked:bg-gray-100
|
||||||
${cameraModeMutation.isPending ? "opacity-60 cursor-not-allowed" : "cursor-pointer"}`}
|
${cameraModeMutation.isPending ? "opacity-60 cursor-not-allowed" : "cursor-pointer"}`}
|
||||||
>
|
>
|
||||||
{el === "day" ? "Day" : "Night"}
|
{capitalize(el)}
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
|
|||||||
67
src/components/HotlistList/HotlistList.tsx
Normal file
67
src/components/HotlistList/HotlistList.tsx
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
import { useHotlistData } from "../../hooks/useHotListData";
|
||||||
|
import { useIntegrationsContext } from "../../context/IntegrationsContext";
|
||||||
|
import Card from "../UI/Card";
|
||||||
|
import CardHeader from "../UI/CardHeader";
|
||||||
|
import { toast } from "sonner";
|
||||||
|
import { faTrash } from "@fortawesome/free-solid-svg-icons";
|
||||||
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||||
|
|
||||||
|
const HotlistList = () => {
|
||||||
|
const { state, dispatch } = useIntegrationsContext();
|
||||||
|
const { mutation } = useHotlistData();
|
||||||
|
|
||||||
|
const hotlists = state?.hotlistFiles;
|
||||||
|
|
||||||
|
const handleDeleteClick = async (filename: string) => {
|
||||||
|
await mutation.mutateAsync(filename);
|
||||||
|
dispatch({ type: "DELETEHOTLIST", payload: filename });
|
||||||
|
toast.success(`${filename} successfully deleted`);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Card className="p-4">
|
||||||
|
<CardHeader title="Uploaded hotlists" />
|
||||||
|
{hotlists?.length > 0 ? (
|
||||||
|
<ul className="px-2">
|
||||||
|
{hotlists?.map((hotlist) => (
|
||||||
|
<li
|
||||||
|
key={hotlist.filename}
|
||||||
|
className="flex flex-row justify-between my-3 items-center border-b border-gray-700"
|
||||||
|
>
|
||||||
|
<div>
|
||||||
|
<p className="text-xl">{hotlist.filename}</p>
|
||||||
|
<div className="flex flex-row gap-3">
|
||||||
|
<div>
|
||||||
|
<p className="text-gray-400">
|
||||||
|
Number of records: <span>{hotlist.rowCount}</span>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<p className="text-gray-400">
|
||||||
|
File Size (bytes): <span>{hotlist.fileSizeBytes}</span>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button onClick={() => handleDeleteClick(hotlist.filename)}>
|
||||||
|
<FontAwesomeIcon icon={faTrash} />
|
||||||
|
</button>
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
) : (
|
||||||
|
<div className="mt-4 flex flex-col items-center justify-center rounded-2xl border border-slate-800 bg-slate-900/40 p-10 text-center">
|
||||||
|
<div className="mb-3 rounded-xl bg-slate-800 px-3 py-1 text-xs uppercase tracking-wider text-slate-400">
|
||||||
|
No Uploaded Hotlists
|
||||||
|
</div>
|
||||||
|
<p className="max-w-md text-slate-300">
|
||||||
|
<span className="text-emerald-400">Hotlists</span> will appear here once there are uploaded.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</Card>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default HotlistList;
|
||||||
@@ -4,7 +4,7 @@ import { useIntegrationsContext } from "../../context/IntegrationsContext";
|
|||||||
import type { ReducedSightingType } from "../../types/types";
|
import type { ReducedSightingType } from "../../types/types";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||||
import { faFloppyDisk, faPause, faPlay, faStop } from "@fortawesome/free-solid-svg-icons";
|
import { faFloppyDisk, faPause, faPlay, faStop, faArrowRotateRight } from "@fortawesome/free-solid-svg-icons";
|
||||||
import VehicleSessionItem from "../UI/VehicleSessionItem";
|
import VehicleSessionItem from "../UI/VehicleSessionItem";
|
||||||
import { useCameraBlackboard } from "../../hooks/useCameraBlackboard";
|
import { useCameraBlackboard } from "../../hooks/useCameraBlackboard";
|
||||||
|
|
||||||
@@ -70,6 +70,21 @@ const SessionCard = () => {
|
|||||||
if (result.reason === "OK") toast.success("Session saved");
|
if (result.reason === "OK") toast.success("Session saved");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleRestartClick = async () => {
|
||||||
|
const result = await mutation.mutateAsync({
|
||||||
|
operation: "INSERT",
|
||||||
|
path: "sessionStats",
|
||||||
|
value: [],
|
||||||
|
});
|
||||||
|
await mutation.mutateAsync({
|
||||||
|
operation: "SAVE",
|
||||||
|
path: "",
|
||||||
|
value: null,
|
||||||
|
});
|
||||||
|
if (result.reason === "OK") toast.success("Session restarted");
|
||||||
|
dispatch({ type: "SESSIONRESTART", payload: [] });
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card className="p-4 col-span-3">
|
<Card className="p-4 col-span-3">
|
||||||
<CardHeader title="Session" />
|
<CardHeader title="Session" />
|
||||||
@@ -85,6 +100,17 @@ const SessionCard = () => {
|
|||||||
<p>{sessionStarted ? "End Session" : "Start Session"}</p>
|
<p>{sessionStarted ? "End Session" : "Start Session"}</p>
|
||||||
</div>
|
</div>
|
||||||
</button>
|
</button>
|
||||||
|
{sessionStarted && (
|
||||||
|
<button
|
||||||
|
className={`bg-none text-white px-4 py-2 rounded transition w-full border border-gray-500 hover:bg-gray-500 hover:text-gray-900`}
|
||||||
|
onClick={handleRestartClick}
|
||||||
|
>
|
||||||
|
<div className="flex flex-row gap-3 items-center justify-self-center">
|
||||||
|
<FontAwesomeIcon icon={faArrowRotateRight} />
|
||||||
|
<p>Restart Session</p>
|
||||||
|
</div>
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
<div className="flex flex-col lg:flex-row gap-5">
|
<div className="flex flex-col lg:flex-row gap-5">
|
||||||
{sessionStarted && (
|
{sessionStarted && (
|
||||||
<button
|
<button
|
||||||
|
|||||||
@@ -183,7 +183,7 @@ const ChannelFields = ({ touched, isSubmitting, format }: ChannelFieldsProps) =>
|
|||||||
className="p-2 border border-gray-400 rounded-lg text-white bg-[#253445] w-full md:w-60"
|
className="p-2 border border-gray-400 rounded-lg text-white bg-[#253445] w-full md:w-60"
|
||||||
>
|
>
|
||||||
<option value={"UTC"}>UTC</option>
|
<option value={"UTC"}>UTC</option>
|
||||||
<option value={"local"}>Local</option>
|
<option value={"LOCAL"}>Local</option>
|
||||||
</Field>
|
</Field>
|
||||||
</FormGroup>
|
</FormGroup>
|
||||||
<FormGroup>
|
<FormGroup>
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import { CAM_BASE } from "../../../utils/config";
|
|||||||
|
|
||||||
const NPEDHotlist = () => {
|
const NPEDHotlist = () => {
|
||||||
const { uploadSettings } = useSystemConfig();
|
const { uploadSettings } = useSystemConfig();
|
||||||
|
|
||||||
const initialValue = {
|
const initialValue = {
|
||||||
file: null,
|
file: null,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -37,41 +37,32 @@ const ModemSettings = () => {
|
|||||||
const handleSubmit = async (values: ModemSettingsType) => {
|
const handleSubmit = async (values: ModemSettingsType) => {
|
||||||
const invalidPrimary = ValidateIPaddress(values.serverPrimary);
|
const invalidPrimary = ValidateIPaddress(values.serverPrimary);
|
||||||
const invalidSecondary = ValidateIPaddress(values.serverSecondary);
|
const invalidSecondary = ValidateIPaddress(values.serverSecondary);
|
||||||
|
|
||||||
if (invalidPrimary || invalidSecondary) {
|
if (invalidPrimary || invalidSecondary) {
|
||||||
toast.error(invalidPrimary || invalidSecondary, {
|
toast.error(invalidPrimary || invalidSecondary, {
|
||||||
id: "invalid-ip",
|
id: "invalid-ip",
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const fields = [
|
||||||
|
{ property: "propAPN", value: values.apn },
|
||||||
|
{ property: "propPassword", value: values.password },
|
||||||
|
{ property: "propUsername", value: values.username },
|
||||||
|
{ property: "propMode", value: showSettings ? "AUTO" : "MANUAL" },
|
||||||
|
{ property: "propNameServerPrimary", value: values.serverPrimary },
|
||||||
|
];
|
||||||
|
|
||||||
|
if (values.serverSecondary?.trim()) {
|
||||||
|
fields.push({
|
||||||
|
property: "propNameServerSecondary",
|
||||||
|
value: values.serverSecondary.trim(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const modemConfig = {
|
const modemConfig = {
|
||||||
id: "ModemAndWifiManager-modem",
|
id: "ModemAndWifiManager-modem",
|
||||||
fields: [
|
fields,
|
||||||
{
|
|
||||||
property: "propAPN",
|
|
||||||
value: values.apn,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
property: "propPassword",
|
|
||||||
value: values.password,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
property: "propUsername",
|
|
||||||
value: values.username,
|
|
||||||
},
|
|
||||||
|
|
||||||
{
|
|
||||||
property: "propMode",
|
|
||||||
value: showSettings ? "AUTO" : "MANUAL",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
property: "propNameServerPrimary",
|
|
||||||
value: values.serverPrimary,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
property: "propNameServerSecondary",
|
|
||||||
value: values.serverSecondary,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const response = await modemMutation.mutateAsync(modemConfig);
|
const response = await modemMutation.mutateAsync(modemConfig);
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ const SightingModal = ({ isSightingModalOpen, handleClose, sighting, onDelete }:
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<ModalComponent isModalOpen={isSightingModalOpen} close={handleClose}>
|
<ModalComponent isModalOpen={isSightingModalOpen} close={handleClose}>
|
||||||
<div className="max-w-screen-lg mx-auto py-4 px-2">
|
<div className="mx-auto py-4 px-6 overflow-y-scroll">
|
||||||
<div className="border-b border-gray-600 mb-4">
|
<div className="border-b border-gray-600 mb-4">
|
||||||
<h2 className="text-lg md:text-xl font-semibold">Sighting Details</h2>
|
<h2 className="text-lg md:text-xl font-semibold">Sighting Details</h2>
|
||||||
</div>
|
</div>
|
||||||
@@ -134,7 +134,7 @@ const SightingModal = ({ isSightingModalOpen, handleClose, sighting, onDelete }:
|
|||||||
{isNPEDHitB && <img src={NPED_CAT_B} alt="hotlistHit" className="h-20 object-contain rounded-md" />}
|
{isNPEDHitB && <img src={NPED_CAT_B} alt="hotlistHit" className="h-20 object-contain rounded-md" />}
|
||||||
{isNPEDHitC && <img src={NPED_CAT_C} alt="hotlistHit" className="h-20 object-contain rounded-md" />}
|
{isNPEDHitC && <img src={NPED_CAT_C} alt="hotlistHit" className="h-20 object-contain rounded-md" />}
|
||||||
</div>
|
</div>
|
||||||
{hotlistNames && (
|
{hotlistNames && hotlistNames.length > 0 && (
|
||||||
<div className="flex flex-col border-b border-gray-600 mb-4">
|
<div className="flex flex-col border-b border-gray-600 mb-4">
|
||||||
<p className="text-gray-300">Hotlists</p>
|
<p className="text-gray-300">Hotlists</p>
|
||||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-x-[90%] lg:gap-x-[15%] w-[50%]">
|
<div className="grid grid-cols-1 md:grid-cols-2 gap-x-[90%] lg:gap-x-[15%] w-[50%]">
|
||||||
@@ -148,11 +148,11 @@ const SightingModal = ({ isSightingModalOpen, handleClose, sighting, onDelete }:
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
<div className="flex flex-col lg:flex-row items-center gap-3">
|
<div className="flex flex-col lg:flex-row items-center gap-3 ">
|
||||||
<img
|
<img
|
||||||
src={sighting?.overviewUrl}
|
src={sighting?.overviewUrl}
|
||||||
alt="overview patch"
|
alt="overview patch"
|
||||||
className="w-full h-56 sm:h-72 md:h-96 rounded-lg object-cover border border-gray-700"
|
className="w-full h-56 sm:h-72 md:h-72 rounded-lg object-cover border border-gray-700"
|
||||||
/>
|
/>
|
||||||
<aside className="w-full lg:w-80 bg-gray-800/70 text-white rounded-xl py-4 px-2 border h-[70%] border-gray-700">
|
<aside className="w-full lg:w-80 bg-gray-800/70 text-white rounded-xl py-4 px-2 border h-[70%] border-gray-700">
|
||||||
<h3 className="text-base md:text-lg font-semibold pb-2 border-b border-gray-700">Vehicle Info</h3>
|
<h3 className="text-base md:text-lg font-semibold pb-2 border-b border-gray-700">Vehicle Info</h3>
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ const ModalComponent = ({ isModalOpen, children, close }: ModalComponentProps) =
|
|||||||
<Modal
|
<Modal
|
||||||
isOpen={isModalOpen}
|
isOpen={isModalOpen}
|
||||||
onRequestClose={close}
|
onRequestClose={close}
|
||||||
className="bg-[#1e2a38] p-6 rounded-lg shadow-lg max-w-[80%] mx-auto mt-[1%] md:w-[70%] md:h-[95%] z-[100] overflow-y-auto max-h-screen"
|
className="bg-[#1e2a38] p-3 rounded-lg shadow-lg w-[95%] mt-[2%] md:w-[60%] h-[100%] md:h-[95%] lg:h-[85%] z-[100] overflow-y-auto"
|
||||||
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"
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { useEffect, useReducer, type ReactNode } from "react";
|
|||||||
import { IntegrationsContext } from "../IntegrationsContext";
|
import { IntegrationsContext } from "../IntegrationsContext";
|
||||||
import { useCameraBlackboard } from "../../hooks/useCameraBlackboard";
|
import { useCameraBlackboard } from "../../hooks/useCameraBlackboard";
|
||||||
import { initialState, reducer } from "../reducers/IntegrationsContextReducer";
|
import { initialState, reducer } from "../reducers/IntegrationsContextReducer";
|
||||||
|
import { useHotlistData } from "../../hooks/useHotListData";
|
||||||
|
|
||||||
type IntegrationsProviderType = {
|
type IntegrationsProviderType = {
|
||||||
children: ReactNode;
|
children: ReactNode;
|
||||||
@@ -10,6 +11,7 @@ type IntegrationsProviderType = {
|
|||||||
export const IntegrationsProvider = ({ children }: IntegrationsProviderType) => {
|
export const IntegrationsProvider = ({ children }: IntegrationsProviderType) => {
|
||||||
const [state, dispatch] = useReducer(reducer, initialState);
|
const [state, dispatch] = useReducer(reducer, initialState);
|
||||||
const { mutation } = useCameraBlackboard();
|
const { mutation } = useCameraBlackboard();
|
||||||
|
const { query } = useHotlistData();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let isMounted = true;
|
let isMounted = true;
|
||||||
@@ -50,6 +52,13 @@ export const IntegrationsProvider = ({ children }: IntegrationsProviderType) =>
|
|||||||
};
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const fetchHotlistData = async () => {
|
||||||
|
dispatch({ type: "SETHOTLISTS", payload: query?.data?.hotlists });
|
||||||
|
};
|
||||||
|
fetchHotlistData();
|
||||||
|
}, [query?.data]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<IntegrationsContext.Provider
|
<IntegrationsContext.Provider
|
||||||
value={{
|
value={{
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import type { NPEDACTION, NPEDSTATE } from "../../types/types";
|
import type { NPEDACTION, NPEDSTATE } from "../../types/types";
|
||||||
|
|
||||||
export const initialState = {
|
export const initialState = {
|
||||||
sessionStarted: false,
|
sessionStarted: true,
|
||||||
sessionList: [],
|
sessionList: [],
|
||||||
sessionPaused: false,
|
sessionPaused: false,
|
||||||
savedSightings: [],
|
savedSightings: [],
|
||||||
@@ -12,6 +12,7 @@ export const initialState = {
|
|||||||
catC: true,
|
catC: true,
|
||||||
catD: false,
|
catD: false,
|
||||||
},
|
},
|
||||||
|
hotlistFiles: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
export function reducer(state: NPEDSTATE, action: NPEDACTION) {
|
export function reducer(state: NPEDSTATE, action: NPEDACTION) {
|
||||||
@@ -36,6 +37,11 @@ export function reducer(state: NPEDSTATE, action: NPEDACTION) {
|
|||||||
...state,
|
...state,
|
||||||
sessionPaused: action.payload,
|
sessionPaused: action.payload,
|
||||||
};
|
};
|
||||||
|
case "SESSIONRESTART":
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
sessionList: action.payload,
|
||||||
|
};
|
||||||
case "ADD":
|
case "ADD":
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
@@ -51,6 +57,17 @@ export function reducer(state: NPEDSTATE, action: NPEDACTION) {
|
|||||||
...state,
|
...state,
|
||||||
iscatEnabled: action.payload,
|
iscatEnabled: action.payload,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
case "SETHOTLISTS":
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
hotlistFiles: action.payload,
|
||||||
|
};
|
||||||
|
case "DELETEHOTLIST":
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
hotlistFiles: state.hotlistFiles.filter((hotlist) => hotlist.filename !== action.payload),
|
||||||
|
};
|
||||||
default:
|
default:
|
||||||
return { ...state };
|
return { ...state };
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ const getCameraMode = async (options: { camera: string }) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const updateCameraMode = async (options: { camera: string; mode: string }) => {
|
const updateCameraMode = async (options: { camera: string; mode: string }) => {
|
||||||
|
console.log(options.mode);
|
||||||
const dayNightPayload = {
|
const dayNightPayload = {
|
||||||
id: options.camera,
|
id: options.camera,
|
||||||
fields: [
|
fields: [
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ async function fetchSnapshot(cameraSide: string): Promise<Blob> {
|
|||||||
return response.blob();
|
return response.blob();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Draw an ImageBitmap to canvas with aspect-fill (like object-fit: cover) */
|
|
||||||
function drawBitmapToCanvas(canvas: HTMLCanvasElement, bitmap: ImageBitmap) {
|
function drawBitmapToCanvas(canvas: HTMLCanvasElement, bitmap: ImageBitmap) {
|
||||||
const ctx = canvas.getContext("2d");
|
const ctx = canvas.getContext("2d");
|
||||||
if (!ctx) return;
|
if (!ctx) return;
|
||||||
@@ -42,18 +41,14 @@ function drawBitmapToCanvas(canvas: HTMLCanvasElement, bitmap: ImageBitmap) {
|
|||||||
let drawWidth = width;
|
let drawWidth = width;
|
||||||
let drawHeight = height;
|
let drawHeight = height;
|
||||||
|
|
||||||
// aspect-fit calculation (no cropping)
|
|
||||||
if (srcAspect > dstAspect) {
|
if (srcAspect > dstAspect) {
|
||||||
// image is wider → fit to canvas width
|
|
||||||
drawWidth = width;
|
drawWidth = width;
|
||||||
drawHeight = width / srcAspect;
|
drawHeight = width / srcAspect;
|
||||||
} else {
|
} else {
|
||||||
// image is taller → fit to canvas height
|
|
||||||
drawHeight = height;
|
drawHeight = height;
|
||||||
drawWidth = height * srcAspect;
|
drawWidth = height * srcAspect;
|
||||||
}
|
}
|
||||||
|
|
||||||
// center image (adds black borders if aspect ratios differ)
|
|
||||||
const dx = (width - drawWidth) / 50;
|
const dx = (width - drawWidth) / 50;
|
||||||
const dy = (height - drawHeight) / 2;
|
const dy = (height - drawHeight) / 2;
|
||||||
|
|
||||||
@@ -66,7 +61,6 @@ export function useGetOverviewSnapshot(side: string) {
|
|||||||
const canvasRef = useRef<HTMLCanvasElement | null>(null);
|
const canvasRef = useRef<HTMLCanvasElement | null>(null);
|
||||||
const latestBitmapRef = useRef<ImageBitmap | null>(null);
|
const latestBitmapRef = useRef<ImageBitmap | null>(null);
|
||||||
|
|
||||||
// Redraw helper; always draws the current bitmap if available
|
|
||||||
const draw = useCallback(() => {
|
const draw = useCallback(() => {
|
||||||
const canvas = canvasRef.current;
|
const canvas = canvasRef.current;
|
||||||
const bmp = latestBitmapRef.current;
|
const bmp = latestBitmapRef.current;
|
||||||
@@ -82,16 +76,15 @@ export function useGetOverviewSnapshot(side: string) {
|
|||||||
} = useQuery({
|
} = useQuery({
|
||||||
queryKey: ["overviewSnapshot", side],
|
queryKey: ["overviewSnapshot", side],
|
||||||
queryFn: () => fetchSnapshot(side),
|
queryFn: () => fetchSnapshot(side),
|
||||||
// Poll ~4 fps when visible; pause when tab hidden
|
|
||||||
refetchInterval: () => (document.visibilityState === "visible" ? 250 : false),
|
refetchInterval: () => (document.visibilityState === "visible" ? 250 : false),
|
||||||
refetchOnWindowFocus: false,
|
refetchOnWindowFocus: false,
|
||||||
// Avoid keeping lots of blobs around in cache
|
|
||||||
gcTime: 0, // v5 name (cacheTime in v4)
|
gcTime: 0,
|
||||||
staleTime: 0,
|
staleTime: 0,
|
||||||
retry: false, // or a small number if you prefer retries
|
retry: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Convert Blob -> ImageBitmap and draw
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let cancelled = false;
|
let cancelled = false;
|
||||||
if (!snapshotBlob) return;
|
if (!snapshotBlob) return;
|
||||||
@@ -104,13 +97,11 @@ export function useGetOverviewSnapshot(side: string) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dispose previous bitmap to free memory
|
|
||||||
if (latestBitmapRef.current) {
|
if (latestBitmapRef.current) {
|
||||||
latestBitmapRef.current.close();
|
latestBitmapRef.current.close();
|
||||||
}
|
}
|
||||||
latestBitmapRef.current = bitmap;
|
latestBitmapRef.current = bitmap;
|
||||||
|
|
||||||
// Draw now (and again on next resize)
|
|
||||||
draw();
|
draw();
|
||||||
} catch {
|
} catch {
|
||||||
// noop — fetch handler surfaces the main error path
|
// noop — fetch handler surfaces the main error path
|
||||||
@@ -122,12 +113,11 @@ export function useGetOverviewSnapshot(side: string) {
|
|||||||
};
|
};
|
||||||
}, [snapshotBlob, draw]);
|
}, [snapshotBlob, draw]);
|
||||||
|
|
||||||
// Redraw on resize & DPR changes
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const onResize = () => draw();
|
const onResize = () => draw();
|
||||||
const onDPR = () => draw();
|
const onDPR = () => draw();
|
||||||
window.addEventListener("resize", onResize);
|
window.addEventListener("resize", onResize);
|
||||||
// Listen for DPR changes (some browsers support this)
|
|
||||||
const mql = window.matchMedia(`(resolution: ${window.devicePixelRatio}dppx)`);
|
const mql = window.matchMedia(`(resolution: ${window.devicePixelRatio}dppx)`);
|
||||||
mql.addEventListener?.("change", onDPR);
|
mql.addEventListener?.("change", onDPR);
|
||||||
return () => {
|
return () => {
|
||||||
@@ -137,14 +127,13 @@ export function useGetOverviewSnapshot(side: string) {
|
|||||||
}, [draw]);
|
}, [draw]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const el = canvasRef.current?.parentElement; // the box
|
const el = canvasRef.current?.parentElement;
|
||||||
if (!el) return;
|
if (!el) return;
|
||||||
const ro = new ResizeObserver(() => draw()); // your draw() calls aspect-fit logic
|
const ro = new ResizeObserver(() => draw());
|
||||||
ro.observe(el);
|
ro.observe(el);
|
||||||
return () => ro.disconnect();
|
return () => ro.disconnect();
|
||||||
}, [draw]);
|
}, [draw]);
|
||||||
|
|
||||||
// Cleanup on unmount
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
return () => {
|
return () => {
|
||||||
if (latestBitmapRef.current) {
|
if (latestBitmapRef.current) {
|
||||||
@@ -154,7 +143,6 @@ export function useGetOverviewSnapshot(side: string) {
|
|||||||
};
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
// Optional: normalize error type
|
|
||||||
const typedError = error instanceof Error ? error : undefined;
|
const typedError = error instanceof Error ? error : undefined;
|
||||||
|
|
||||||
return { canvasRef, isError, error: typedError, isPending };
|
return { canvasRef, isError, error: typedError, isPending };
|
||||||
|
|||||||
28
src/hooks/useHotListData.ts
Normal file
28
src/hooks/useHotListData.ts
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
import { useMutation, useQuery } from "@tanstack/react-query";
|
||||||
|
import { CAM_BASE } from "../utils/config";
|
||||||
|
|
||||||
|
const fetchHotlists = async () => {
|
||||||
|
const response = await fetch(`${CAM_BASE}/Hotlist-csv-metadata`);
|
||||||
|
if (!response.ok) throw new Error("Cannot reach hotlist endpoint");
|
||||||
|
return response.json();
|
||||||
|
};
|
||||||
|
|
||||||
|
const deleteHotlist = async (filename: string) => {
|
||||||
|
const response = await fetch(`${CAM_BASE}/Hotlist-csv-delete?filename=${filename}`);
|
||||||
|
if (!response.ok) throw new Error(`Cannot delte hotlist: ${filename}`);
|
||||||
|
return response.json();
|
||||||
|
};
|
||||||
|
|
||||||
|
export const useHotlistData = () => {
|
||||||
|
const query = useQuery({
|
||||||
|
queryKey: ["fetchHotlists"],
|
||||||
|
queryFn: fetchHotlists,
|
||||||
|
});
|
||||||
|
|
||||||
|
const mutation = useMutation({
|
||||||
|
mutationKey: ["deleteHotlist"],
|
||||||
|
mutationFn: (filename: string) => deleteHotlist(filename),
|
||||||
|
});
|
||||||
|
|
||||||
|
return { query, mutation };
|
||||||
|
};
|
||||||
@@ -11,6 +11,7 @@ import { useNPEDAuth } from "../hooks/useNPEDAuth";
|
|||||||
import SoundSettingsCard from "../components/SettingForms/Sound/SoundSettingsCard";
|
import SoundSettingsCard from "../components/SettingForms/Sound/SoundSettingsCard";
|
||||||
import SoundUploadCard from "../components/SettingForms/Sound/SoundUploadCard";
|
import SoundUploadCard from "../components/SettingForms/Sound/SoundUploadCard";
|
||||||
import NPEDCategoryPopup from "../components/PopupSettings/NPEDCategoryPopup";
|
import NPEDCategoryPopup from "../components/PopupSettings/NPEDCategoryPopup";
|
||||||
|
import HotlistList from "../components/HotlistList/HotlistList";
|
||||||
|
|
||||||
const SystemSettings = () => {
|
const SystemSettings = () => {
|
||||||
useNPEDAuth();
|
useNPEDAuth();
|
||||||
@@ -40,6 +41,7 @@ const SystemSettings = () => {
|
|||||||
<NPEDCard />
|
<NPEDCard />
|
||||||
<NPEDHotlistCard />
|
<NPEDHotlistCard />
|
||||||
<NPEDCategoryPopup />
|
<NPEDCategoryPopup />
|
||||||
|
<HotlistList />
|
||||||
</div>
|
</div>
|
||||||
</TabPanel>
|
</TabPanel>
|
||||||
<TabPanel>
|
<TabPanel>
|
||||||
|
|||||||
@@ -417,6 +417,12 @@ export type QueuedHit = {
|
|||||||
|
|
||||||
export type DedupedSightings = ReducedSightingType[];
|
export type DedupedSightings = ReducedSightingType[];
|
||||||
|
|
||||||
|
export type HotlistFile = {
|
||||||
|
fileSizeBytes: number;
|
||||||
|
filename: string;
|
||||||
|
rowCount: number;
|
||||||
|
};
|
||||||
|
|
||||||
export type NPEDSTATE = {
|
export type NPEDSTATE = {
|
||||||
sessionStarted: boolean;
|
sessionStarted: boolean;
|
||||||
sessionList: ReducedSightingType[];
|
sessionList: ReducedSightingType[];
|
||||||
@@ -424,6 +430,7 @@ export type NPEDSTATE = {
|
|||||||
savedSightings: DedupedSightings;
|
savedSightings: DedupedSightings;
|
||||||
npedUser: NPEDUser;
|
npedUser: NPEDUser;
|
||||||
iscatEnabled: CategoryPopups;
|
iscatEnabled: CategoryPopups;
|
||||||
|
hotlistFiles: HotlistFile[];
|
||||||
};
|
};
|
||||||
|
|
||||||
export type NPEDACTION = {
|
export type NPEDACTION = {
|
||||||
|
|||||||
Reference in New Issue
Block a user