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 (