From 1137c3b4cc835d5d7a746fcdb42abd6cc2e92e48 Mon Sep 17 00:00:00 2001 From: Ryan Chen Date: Fri, 26 Sep 2025 09:18:32 -0400 Subject: [PATCH] Toggling posted and deleting --- ppq-frontend/src/Card.tsx | 34 ++++++++++++++++++++++++++++++++-- ppq-frontend/src/ListPage.tsx | 7 +++++++ 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/ppq-frontend/src/Card.tsx b/ppq-frontend/src/Card.tsx index 322a693..db59c3d 100644 --- a/ppq-frontend/src/Card.tsx +++ b/ppq-frontend/src/Card.tsx @@ -1,5 +1,6 @@ import { useEffect, useState } from "react"; +import axios from "axios"; import { NavLink, Link } from "react-router"; type CardProps = { @@ -9,6 +10,8 @@ type CardProps = { contributor: string; uuid: string; filepath: string; + posted: boolean; + handleDelete: (uuid) => void; }; export const Card = ({ @@ -18,14 +21,30 @@ export const Card = ({ contributor, uuid, filepath, + posted, + handleDelete, }: CardProps) => { const [showMenu, setShowMenu] = useState(false); + const [cardPosted, setCardPosted] = useState(posted); + + const handleMarkPosted = () => { + setCardPosted(!cardPosted); + axios.post(`/api/pictures/post?uuid=${uuid}`); + }; + console.log(filepath); return (
-

{title}

+

+ {title}{" "} + {cardPosted && ( + + posted + + )} +

submitted {timestamp} by{" "} {contributor} @@ -61,11 +80,22 @@ export const Card = ({

-
+
handleMarkPosted()} + >

mark as posted

+
handleDelete(uuid)} + > +

+ Delete this post +

+
)}
diff --git a/ppq-frontend/src/ListPage.tsx b/ppq-frontend/src/ListPage.tsx index 27d4b8b..e915876 100644 --- a/ppq-frontend/src/ListPage.tsx +++ b/ppq-frontend/src/ListPage.tsx @@ -7,6 +7,11 @@ import { Card } from "./Card"; export const ListPage = () => { const [petPictures, setPetPictures] = useState([]); + const handleDelete = (uuid: str) => { + setPetPictures(petPictures.filter((post) => post.uuid != uuid)); + axios.delete(`/api/pictures/${uuid}`); + }; + useEffect(() => { axios .get("/api/pictures") @@ -24,6 +29,8 @@ export const ListPage = () => { timestamp={picture.created_at} contributor={picture.contributor} filepath={picture.filepath} + posted={picture.posted} + handleDelete={handleDelete} /> ))}