From 9148f894e02bf43775e18fc873a9deab5c36220c Mon Sep 17 00:00:00 2001 From: realtradam Date: Sat, 27 Jul 2024 19:40:27 -0400 Subject: add delete button to frontend --- frontend/src/pages/Home.tsx | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/frontend/src/pages/Home.tsx b/frontend/src/pages/Home.tsx index e0866a4..bada22d 100644 --- a/frontend/src/pages/Home.tsx +++ b/frontend/src/pages/Home.tsx @@ -1,4 +1,4 @@ -import { useState, useEffect } from "react"; +import { useState, useEffect, FormEvent } from "react"; type article = { id: number; @@ -14,6 +14,7 @@ type articleSearch = { value: string | null; }; + export default function Home({ articleSearch, }: { @@ -22,6 +23,26 @@ export default function Home({ const [articles, setArticles] = useState([]); const [allArticles, setAllArticles] = useState([]); + const handleDelete = async (e: FormEvent) => { + e.preventDefault(); //stops submit from happening + + const target = e.target as typeof e.target & { + id: { value: string }; + }; + + const response = await fetch( + `${import.meta.env.VITE_API_TITLE}/api/v1/article/delete/${target.id.value}`, + { + credentials: "include", + method: "get", + }, + ); + if (!response.ok) { + console.log(response); + alert("check console for error"); + } + }; + // pull data when new search is given useEffect(() => { let url; @@ -71,9 +92,12 @@ export default function Home({ Edit {/*th:href="@{/articles/delete/{articleId}(articleId=${article.id})}"*/} - +
+ + +
-- cgit v1.2.3