From 44962e7d81f96b5f25c571f91da24165937c5468 Mon Sep 17 00:00:00 2001 From: Toba Ojo Date: Mon, 13 Oct 2025 11:48:10 +0100 Subject: [PATCH] - fixed but to delete specific alert item - need to remove rawcamebase from config in prod --- src/components/HistoryList/AlertItem.tsx | 26 +++++++++++++++---- src/components/HistoryList/HistoryList.tsx | 21 ++++++++++++--- .../SightingModal/SightingModal.tsx | 11 ++++---- src/utils/config.ts | 5 +--- src/utils/utils.ts | 1 + 5 files changed, 46 insertions(+), 18 deletions(-) diff --git a/src/components/HistoryList/AlertItem.tsx b/src/components/HistoryList/AlertItem.tsx index 48c12ce..ccae950 100644 --- a/src/components/HistoryList/AlertItem.tsx +++ b/src/components/HistoryList/AlertItem.tsx @@ -5,6 +5,7 @@ import InfoBar from "../SightingsWidget/InfoBar"; import { useState } from "react"; import HotListImg from "/Hotlist_Hit.svg"; import { useAlertHitContext } from "../../context/AlertHitContext"; +import { useCameraBlackboard } from "../../hooks/useCameraBlackboard"; import NPED_CAT_A from "/NPED_Cat_A.svg"; import NPED_CAT_B from "/NPED_Cat_B.svg"; import NPED_CAT_C from "/NPED_Cat_C.svg"; @@ -17,6 +18,7 @@ type AlertItemProps = { const AlertItem = ({ item }: AlertItemProps) => { const [isModalOpen, setIsModalOpen] = useState(false); const { dispatch } = useAlertHitContext(); + const { mutation } = useCameraBlackboard(); // const {d} = useCameraBlackboard(); const motionAway = (item?.motion ?? "").toUpperCase() === "AWAY"; @@ -34,12 +36,26 @@ const AlertItem = ({ item }: AlertItemProps) => { 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 }); }; return (
-
+
{ {isNPEDHitA && ( hotlistHit )} {isNPEDHitB && ( hotlistHit )} {isNPEDHitC && ( hotlistHit )} diff --git a/src/components/HistoryList/HistoryList.tsx b/src/components/HistoryList/HistoryList.tsx index 81f958f..1cd3735 100644 --- a/src/components/HistoryList/HistoryList.tsx +++ b/src/components/HistoryList/HistoryList.tsx @@ -11,9 +11,22 @@ const HistoryList = () => { const { state, dispatch, isLoading, error } = useAlertHitContext(); const { mutation } = useCameraBlackboard(); - const handleDeleteClick = (alertItem: SightingType, idx?: number) => { - dispatch({ type: "REMOVE", payload: alertItem }); - mutation.mutate({ operation: "POP", path: "alertHistory", value: idx }); + const handleDeleteClick = async (deletedItem: SightingType) => { + 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: deletedItem }); }; const handleClearListClick = (listName: CameraBlackBoardOptions) => { @@ -40,7 +53,7 @@ const HistoryList = () => { state?.alertList?.map((alertItem, index) => (
-