import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { useAlertHitContext } from "../../context/AlertHitContext"; import { useCameraBlackboard } from "../../hooks/useCameraBlackboard"; import type { CameraBlackBoardOptions, SightingType } from "../../types/types"; import Card from "../UI/Card"; import CardHeader from "../UI/CardHeader"; import AlertItem from "./AlertItem"; import { faTrash } from "@fortawesome/free-solid-svg-icons"; const HistoryList = () => { const { state, dispatch, isLoading, error } = useAlertHitContext(); const { mutation } = useCameraBlackboard(); 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) => { dispatch({ type: "DELETE", payload: [] }); mutation.mutate({ operation: "DELETE", path: listName.path, }); }; return ( {isLoading &&

Loading...

} {error &&

Error: {error.message}

}
{state?.alertList?.length > 0 ? ( state?.alertList?.map((alertItem, index) => (
)) ) : (

No Alert results

)}
); }; export default HistoryList;