fix order, add delete functionality

This commit is contained in:
2026-09-06 22:57:05 -04:00
parent 04ad21d4b3
commit 567d5e0db0
2 changed files with 47 additions and 14 deletions
+28 -9
View File
@@ -27,9 +27,20 @@ export default function Post() {
}
}, []);
useEffect(() => {
console.log(post);
}, [post]);
function deletePost() {
if (!auth.user || !post) return;
fetch("/api/posts/" + post.slug, {
method: "DELETE",
credentials: "include",
}).then((res) => {
if (!res.ok) {
console.error("Failed to delete post " + res.status);
} else {
navigate("/");
}
});
}
if (post) {
return (
@@ -57,12 +68,20 @@ export default function Post() {
"- updated on " + new Date(post.updatedAt).toLocaleString()}
</p>
{auth.user && (
<p
className="text-sm opacity-50 underline hover:cursor-pointer"
onClick={() => navigate(`/editor/${post.slug}`)}
>
Edit
</p>
<div className="inline-block space-x-2">
<p
className="text-sm opacity-50 underline hover:cursor-pointer inline"
onClick={() => navigate(`/editor/${post.slug}`)}
>
Edit
</p>
<p
className="text-sm opacity-50 underline hover:cursor-pointer inline"
onClick={deletePost}
>
Delete
</p>
</div>
)}
</div>
</Layout>