- fixed but to delete specific alert item

- need to remove rawcamebase from config in prod
This commit is contained in:
2025-10-13 11:48:10 +01:00
parent 9f3674e460
commit 44962e7d81
5 changed files with 46 additions and 18 deletions

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

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

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;
} }
}; };