2025-09-23 16:02:14 +01:00
|
|
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
2025-09-16 11:07:35 +01:00
|
|
|
import { useAlertHitContext } from "../../context/AlertHitContext";
|
2025-09-23 16:02:14 +01:00
|
|
|
import type { SightingType } from "../../types/types";
|
2025-09-16 11:07:35 +01:00
|
|
|
import Card from "../UI/Card";
|
|
|
|
|
import CardHeader from "../UI/CardHeader";
|
|
|
|
|
import AlertItem from "./AlertItem";
|
2025-09-23 16:02:14 +01:00
|
|
|
import { faTrash } from "@fortawesome/free-solid-svg-icons";
|
2025-09-16 11:07:35 +01:00
|
|
|
|
|
|
|
|
const HistoryList = () => {
|
2025-09-23 16:02:14 +01:00
|
|
|
const { state, dispatch } = useAlertHitContext();
|
2025-09-16 14:20:38 +01:00
|
|
|
|
2025-09-23 16:02:14 +01:00
|
|
|
const handleDeleteClick = (alertItem: SightingType) =>
|
|
|
|
|
dispatch({ type: "REMOVE", payload: alertItem });
|
2025-09-16 11:07:35 +01:00
|
|
|
return (
|
|
|
|
|
<Card className="h-100">
|
|
|
|
|
<CardHeader title="Alert History" />
|
|
|
|
|
<div className="flex flex-col gap-1">
|
2025-09-16 14:20:38 +01:00
|
|
|
{state?.alertList?.length > 0 ? (
|
2025-09-16 11:07:35 +01:00
|
|
|
state?.alertList?.map((alertItem, index) => (
|
2025-09-23 16:02:14 +01:00
|
|
|
<div key={index} className="flex flex-row space-x-2">
|
|
|
|
|
<AlertItem item={alertItem} />
|
|
|
|
|
<button onClick={() => handleDeleteClick(alertItem)}>
|
|
|
|
|
<div className="p-4">
|
|
|
|
|
<FontAwesomeIcon icon={faTrash} size="2x" />
|
|
|
|
|
</div>
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
2025-09-16 11:07:35 +01:00
|
|
|
))
|
|
|
|
|
) : (
|
2025-09-16 14:20:38 +01:00
|
|
|
<p>No Alert results</p>
|
2025-09-16 11:07:35 +01:00
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
</Card>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default HistoryList;
|