Merged in develop (pull request #18)

Develop
This commit is contained in:
2025-10-13 12:59:49 +00:00
9 changed files with 70 additions and 39 deletions

9
.env
View File

@@ -1,9 +0,0 @@
VITE_BASEURL=http://192.168.75.11/
VITE_CAM_BASE=http://100.118.196.113:8080
VITE_FOLKESTONE_BASE=http://100.116.253.81
VITE_TESTURL=http://100.82.205.44/SightingListRear/sightingSummary?mostRecentRef=-1
VITE_OUTSIDE_BASEURL=http://100.82.205.44
VITE_FOLKESTONE_URL=http://100.116.253.81/mergedHistory/sightingSummary?mostRecentRef=
VITE_MAV_URL=http://192.168.75.11/SightingListFront/sightingSummary?mostRecentRef=
VITE_AGX_BOX_URL=http://100.118.196.113:8080

View File

@@ -104,7 +104,7 @@ const CameraSettingFields = ({
validateOnChange={false} validateOnChange={false}
enableReinitialize enableReinitialize
> >
{({ errors, touched, isSubmitting }) => ( {({ errors, touched }) => (
<Form className="flex flex-col space-y-6 p-2"> <Form className="flex flex-col space-y-6 p-2">
<div className="flex flex-col space-y-2 relative"> <div className="flex flex-col space-y-2 relative">
<label htmlFor="friendlyName">Name</label> <label htmlFor="friendlyName">Name</label>
@@ -119,6 +119,7 @@ const CameraSettingFields = ({
type="text" type="text"
className="p-2 border border-gray-400 rounded-lg" className="p-2 border border-gray-400 rounded-lg"
placeholder="Enter camera name" placeholder="Enter camera name"
disabled
/> />
</div> </div>
@@ -135,7 +136,7 @@ const CameraSettingFields = ({
type="text" type="text"
className="p-2 border border-gray-400 rounded-lg" className="p-2 border border-gray-400 rounded-lg"
placeholder="RTSP://..." placeholder="RTSP://..."
autoComplete="street-address" disabled
/> />
</div> </div>
@@ -153,6 +154,7 @@ const CameraSettingFields = ({
className="p-2 border border-gray-400 rounded-lg" className="p-2 border border-gray-400 rounded-lg"
placeholder="Enter user name" placeholder="Enter user name"
autoComplete="username" autoComplete="username"
disabled
/> />
</div> </div>
@@ -170,7 +172,7 @@ const CameraSettingFields = ({
type={showPwd ? "text" : "password"} type={showPwd ? "text" : "password"}
className="p-2 border border-gray-400 rounded-lg w-full " className="p-2 border border-gray-400 rounded-lg w-full "
placeholder="Enter password" placeholder="Enter password"
autoComplete="new-password" disabled
/> />
<FontAwesomeIcon <FontAwesomeIcon
type="button" type="button"
@@ -207,15 +209,20 @@ const CameraSettingFields = ({
</div> </div>
<div className="mt-3"> <div className="mt-3">
{updateCameraConfigError ? ( {updateCameraConfigError ? (
<button className="bg-red-500 text-white rounded-lg p-2 mx-auto h-[100%] w-full"> <button
className="bg-red-500 text-white rounded-lg p-2 mx-auto h-[100%] w-full"
disabled
>
Retry Retry
</button> </button>
) : ( ) : (
<button <button
type="submit" type="submit"
className="bg-[#26B170] text-white rounded-lg p-2 mx-auto h-[100%] w-full" className="bg-blue-700 text-white rounded-lg p-2 mx-auto h-[100%] w-full"
disabled
> >
{isSubmitting ? "Saving" : "Save settings"} {/* {isSubmitting ? "Saving" : "Save settings"} bg-[#26B170] */}
{"Disabled: Coming soon"}
</button> </button>
)} )}
</div> </div>

View File

@@ -5,6 +5,7 @@ import InfoBar from "../SightingsWidget/InfoBar";
import { useState } from "react"; import { useState } from "react";
import HotListImg from "/Hotlist_Hit.svg"; import HotListImg from "/Hotlist_Hit.svg";
import { useAlertHitContext } from "../../context/AlertHitContext"; import { useAlertHitContext } from "../../context/AlertHitContext";
import { useCameraBlackboard } from "../../hooks/useCameraBlackboard";
import NPED_CAT_A from "/NPED_Cat_A.svg"; import NPED_CAT_A from "/NPED_Cat_A.svg";
import NPED_CAT_B from "/NPED_Cat_B.svg"; import NPED_CAT_B from "/NPED_Cat_B.svg";
import NPED_CAT_C from "/NPED_Cat_C.svg"; import NPED_CAT_C from "/NPED_Cat_C.svg";
@@ -17,6 +18,7 @@ type AlertItemProps = {
const AlertItem = ({ item }: AlertItemProps) => { const AlertItem = ({ item }: AlertItemProps) => {
const [isModalOpen, setIsModalOpen] = useState(false); const [isModalOpen, setIsModalOpen] = useState(false);
const { dispatch } = useAlertHitContext(); const { dispatch } = useAlertHitContext();
const { mutation } = useCameraBlackboard();
// const {d} = useCameraBlackboard(); // const {d} = useCameraBlackboard();
const motionAway = (item?.motion ?? "").toUpperCase() === "AWAY"; const motionAway = (item?.motion ?? "").toUpperCase() === "AWAY";
@@ -34,12 +36,26 @@ const AlertItem = ({ item }: AlertItemProps) => {
setIsModalOpen(false); setIsModalOpen(false);
}; };
const handleDelete = () => { const handleDelete = async (deletedItem: SightingType | null) => {
const res = await mutation.mutateAsync({
operation: "VIEW",
path: "alertHistory",
});
const oldArray = res?.result;
const updatedArray = oldArray?.filter(
(item: SightingType) => item?.ref !== deletedItem?.ref
);
mutation.mutate({
operation: "INSERT",
path: "alertHistory",
value: updatedArray,
});
dispatch({ type: "REMOVE", payload: item }); dispatch({ type: "REMOVE", payload: item });
}; };
return ( return (
<div className="flex flex-col w-full"> <div className="flex flex-col w-full">
<div className="border border-gray-400 rounded-lg items-center py-1"> <div className="border border-gray-600 rounded-lg items-center py-1">
<InfoBar obj={item} /> <InfoBar obj={item} />
<div <div
className=" flex flex-row p-4 w-full mx-auto justify-between" className=" flex flex-row p-4 w-full mx-auto justify-between"
@@ -55,21 +71,21 @@ const AlertItem = ({ item }: AlertItemProps) => {
{isNPEDHitA && ( {isNPEDHitA && (
<img <img
src={NPED_CAT_A} src={NPED_CAT_A}
alt="hotlistHit" alt="NPEDHITicon"
className="h-20 object-contain rounded-md" className="h-20 object-contain rounded-md"
/> />
)} )}
{isNPEDHitB && ( {isNPEDHitB && (
<img <img
src={NPED_CAT_B} src={NPED_CAT_B}
alt="hotlistHit" alt="NPEDHITicon"
className="h-20 object-contain rounded-md" className="h-20 object-contain rounded-md"
/> />
)} )}
{isNPEDHitC && ( {isNPEDHitC && (
<img <img
src={NPED_CAT_C} src={NPED_CAT_C}
alt="hotlistHit" alt="NPEDHITicon"
className="h-20 object-contain rounded-md" className="h-20 object-contain rounded-md"
/> />
)} )}

View File

@@ -11,9 +11,22 @@ const HistoryList = () => {
const { state, dispatch, isLoading, error } = useAlertHitContext(); const { state, dispatch, isLoading, error } = useAlertHitContext();
const { mutation } = useCameraBlackboard(); const { mutation } = useCameraBlackboard();
const handleDeleteClick = (alertItem: SightingType, idx?: number) => { const handleDeleteClick = async (deletedItem: SightingType) => {
dispatch({ type: "REMOVE", payload: alertItem }); const res = await mutation.mutateAsync({
mutation.mutate({ operation: "POP", path: "alertHistory", value: idx }); operation: "VIEW",
path: "alertHistory",
});
const oldArray = res?.result;
const updatedArray = oldArray?.filter(
(item: SightingType) => item?.ref !== deletedItem?.ref
);
mutation.mutate({
operation: "INSERT",
path: "alertHistory",
value: updatedArray,
});
dispatch({ type: "REMOVE", payload: deletedItem });
}; };
const handleClearListClick = (listName: CameraBlackBoardOptions) => { const handleClearListClick = (listName: CameraBlackBoardOptions) => {
@@ -40,7 +53,7 @@ const HistoryList = () => {
state?.alertList?.map((alertItem, index) => ( state?.alertList?.map((alertItem, index) => (
<div key={index} className="flex flex-row space-x-2"> <div key={index} className="flex flex-row space-x-2">
<AlertItem item={alertItem} /> <AlertItem item={alertItem} />
<button onClick={() => handleDeleteClick(alertItem, index)}> <button onClick={() => handleDeleteClick(alertItem)}>
<div className="p-4"> <div className="p-4">
<FontAwesomeIcon icon={faTrash} size="2x" /> <FontAwesomeIcon icon={faTrash} size="2x" />
</div> </div>

View File

@@ -16,7 +16,7 @@ type SightingModalProps = {
isSightingModalOpen: boolean; isSightingModalOpen: boolean;
handleClose: () => void; handleClose: () => void;
sighting: SightingType | null; sighting: SightingType | null;
onDelete?: () => void; onDelete?: (deletedItem: SightingType | null) => void;
}; };
const SightingModal = ({ const SightingModal = ({
@@ -47,6 +47,7 @@ const SightingModal = ({
path: "alertHistory", path: "alertHistory",
value: sighting, value: sighting,
}); });
toast.success("Sighting Successfully added to alert list");
} }
dispatch({ type: "ADD", payload: sighting }); dispatch({ type: "ADD", payload: sighting });
@@ -58,9 +59,9 @@ const SightingModal = ({
} }
}; };
const handleDeleteClick = () => { const handleDeleteClick = (deletedItem: SightingType | null) => {
if (!onDelete) return; if (!onDelete) return;
onDelete(); onDelete(deletedItem);
handleClose(); handleClose();
toast.success("Sighting removed from alert list"); toast.success("Sighting removed from alert list");
}; };
@@ -84,7 +85,7 @@ const SightingModal = ({
{onDelete ? ( {onDelete ? (
<button <button
className="inline-flex items-center justify-center gap-2 rounded-lg px-5 py-3 bg-red-600 text-white hover:bg-red-700 w-full md:w-full" className="inline-flex items-center justify-center gap-2 rounded-lg px-5 py-3 bg-red-600 text-white hover:bg-red-700 w-full md:w-full"
onClick={handleDeleteClick} onClick={() => handleDeleteClick(sighting)}
> >
<FontAwesomeIcon icon={faTrash} /> <FontAwesomeIcon icon={faTrash} />
Delete Delete
@@ -234,7 +235,7 @@ const SightingModal = ({
{onDelete ? ( {onDelete ? (
<button <button
className="inline-flex items-center justify-center gap-2 rounded-lg px-5 py-3 bg-red-600 text-white hover:bg-red-700 w-full md:w-full" className="inline-flex items-center justify-center gap-2 rounded-lg px-5 py-3 bg-red-600 text-white hover:bg-red-700 w-full md:w-full"
onClick={handleDeleteClick} onClick={() => handleDeleteClick(sighting)}
> >
<FontAwesomeIcon icon={faTrash} /> <FontAwesomeIcon icon={faTrash} />
Delete Delete

View File

@@ -4,8 +4,10 @@ import type { CameraBlackBoardOptions } from "../types/types";
import { useEffect } from "react"; import { useEffect } from "react";
import { toast } from "sonner"; import { toast } from "sonner";
const camBase = import.meta.env.MODE !== "development" ? CAM_BASE : "";
const getAllBlackboardData = async () => { const getAllBlackboardData = async () => {
const response = await fetch(`${CAM_BASE}/api/blackboard`, { const response = await fetch(`${camBase}/api/blackboard`, {
signal: AbortSignal.timeout(500), signal: AbortSignal.timeout(500),
}); });
if (!response.ok) { if (!response.ok) {
@@ -15,7 +17,7 @@ const getAllBlackboardData = async () => {
}; };
const viewBlackboardData = async (options: CameraBlackBoardOptions) => { const viewBlackboardData = async (options: CameraBlackBoardOptions) => {
const response = await fetch(`${CAM_BASE}/api/blackboard`, { const response = await fetch(`/${camBase}api/blackboard`, {
method: "POST", method: "POST",
headers: { "Content-Type": "application/json" }, headers: { "Content-Type": "application/json" },
body: JSON.stringify(options), body: JSON.stringify(options),

View File

@@ -17,6 +17,7 @@ const fetchCameraSideConfig = async ({ queryKey }: { queryKey: string[] }) => {
const updateCamerasideConfig = async (data: { const updateCamerasideConfig = async (data: {
id: string | number; id: string | number;
friendlyName: string; friendlyName: string;
cameraAddress: string;
}) => { }) => {
const updateUrl = `${base_url}/update-config?id=${data.id}`; const updateUrl = `${base_url}/update-config?id=${data.id}`;
@@ -24,16 +25,17 @@ const updateCamerasideConfig = async (data: {
id: data.friendlyName, id: data.friendlyName,
fields: [ fields: [
{ {
property: "id", property: "propURI",
value: data.friendlyName, value: data.cameraAddress,
}, },
], ],
}; };
console.log(updateConfigPayload);
const response = await fetch(updateUrl, { const response = await fetch(updateUrl, {
method: "POST", method: "POST",
body: JSON.stringify(updateConfigPayload), body: JSON.stringify(updateConfigPayload),
}); });
if (!response.ok) throw new Error("Cannot reach update camera endpoint"); if (!response.ok) throw new Error("Feature unavailable: Coming soon");
}; };
export const useFetchCameraConfig = (cameraSide: string) => { export const useFetchCameraConfig = (cameraSide: string) => {

View File

@@ -1,7 +1,5 @@
const rawCamBase = import.meta.env.VITE_AGX_BOX_URL; const rawCamBase = import.meta.env.VITE_AGX_BOX_URL;
export const CAM_BASE = const environment = import.meta.env.MODE;
rawCamBase && rawCamBase.trim().length > 0
? rawCamBase
: window.location.origin;
export const OUTSIDE_CAM_BASE = import.meta.env.VITE_OUTSIDE_BASEURL; export const CAM_BASE =
environment === "development" ? rawCamBase : window.location.origin;

View File

@@ -136,6 +136,7 @@ export const checkIsHotListHit = (sigthing: SightingType | null) => {
const isHotListHit = Object.values( const isHotListHit = Object.values(
sigthing?.metadata?.hotlistMatches sigthing?.metadata?.hotlistMatches
).includes(true); ).includes(true);
return isHotListHit; return isHotListHit;
} }
}; };