From 27b2be32132f26663e1e9c4bcf592ce9b81e957f Mon Sep 17 00:00:00 2001 From: Hollgy Date: Mon, 25 Mar 2024 14:15:37 +0100 Subject: [PATCH] Boilerplate UI for removal of post, Portal implementation --- .../Components/Buttons/RemovePostButton.tsx | 29 ++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/client-solid/src/Components/Buttons/RemovePostButton.tsx b/client-solid/src/Components/Buttons/RemovePostButton.tsx index 7c00c75..e20e5a5 100644 --- a/client-solid/src/Components/Buttons/RemovePostButton.tsx +++ b/client-solid/src/Components/Buttons/RemovePostButton.tsx @@ -1,5 +1,6 @@ import { useNavigate } from "@solidjs/router"; -import { JSXElement, useContext } from "solid-js"; +import { JSXElement, createEffect, createSignal, useContext } from "solid-js"; +import { Portal } from "solid-js/web"; import { LoginContext } from "../../Context/GlobalState"; import { RemovePostIcon } from "../../Util/Icons"; @@ -11,16 +12,20 @@ export default function RemovePostButton(props: { const navigate = useNavigate(); const login_ctx = useContext(LoginContext)!; + // State to track whether the post has been deleted + const [isDeleted, setIsDeleted] = createSignal(false); + // Function to handle post deletion const handleDeletePost = async (): Promise => { try { const response = await deletePost(props.postId, login_ctx.token()); if (response.ok) { - // If deletion is successful, navigate to "/" or remount the component + // If deletion is successful, set isDeleted to true + setIsDeleted(true); console.log("Post deleted successfully"); - navigate("/"); // Redirect to "/" after successful deletion + // Optional: You can also navigate to "/" after successful deletion + navigate("/"); } else { - // If deletion fails, handle the error console.error("Failed to delete post:", response.statusText); // You may want to show an error message or handle the failure in some other way } @@ -30,6 +35,22 @@ export default function RemovePostButton(props: { } }; + // Effect to display modal when post is deleted + createEffect(() => { + if (isDeleted()) { + // Display modal here + +
+
+ +
+
+
; + } + }); + return (