"use client"; import { useState } from "react"; import { FiTrash2 } from "react-icons/fi"; import "./styles/DeleteButton.css"; export default function DeleteTopicButton({ usn, subject, topic, onDelete }) { const [confirming, setConfirming] = useState(false); const [loading, setLoading] = useState(false); const handleDelete = async () => { setLoading(true); try { const res = await fetch("/api/topic/delete", { method: "DELETE", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ usn, subject, topic }), }); const data = await res.json(); if (!res.ok) { alert(data.error || "Failed to delete topic"); } else { if (onDelete) onDelete(data.subjects); // parent gets updated subjects } } catch (err) { console.error(err); alert("Error deleting topic"); } finally { setLoading(false); setConfirming(false); } }; return (
{!confirming ? ( ) : (

Delete topic?

)}
); }