mirror of
https://github.com/barthuijgen/factorio-sites.git
synced 2025-03-04 15:51:24 +02:00
Added user comment deletion
This commit is contained in:
parent
39626e6ca7
commit
0861c48edf
@ -105,17 +105,13 @@ export const Comments: React.FC<CommentsProps> = ({ blueprint_page_id }) => {
|
||||
fetchTopLevelComments();
|
||||
};
|
||||
|
||||
const onDelete = async (comment_id: string) => {
|
||||
const onDelete = async (comment: CommentWithUsername) => {
|
||||
// eslint-disable-next-line no-restricted-globals
|
||||
if (!confirm("Are you sure you want to delete this comment?")) {
|
||||
return;
|
||||
}
|
||||
if (!confirm("Are you sure you want to delete this comment?")) return;
|
||||
await fetch("/api/blueprint/comment", {
|
||||
method: "DELETE",
|
||||
body: JSON.stringify({ comment_id }),
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({ comment_id: comment.id, comment_author: comment.user_id }),
|
||||
headers: { "Content-Type": "application/json" },
|
||||
});
|
||||
fetchTopLevelComments();
|
||||
};
|
||||
@ -151,7 +147,7 @@ export const Comments: React.FC<CommentsProps> = ({ blueprint_page_id }) => {
|
||||
auth?.role === "admin" ||
|
||||
auth?.user_id === comment.user_id) && (
|
||||
<div className="delete">
|
||||
<button onClick={() => onDelete(comment.id)}>
|
||||
<button onClick={() => onDelete(comment)}>
|
||||
<IoMdTrash />
|
||||
</button>
|
||||
</div>
|
||||
|
@ -8,21 +8,27 @@ const handler = apiHandler(async (req, res, { session }) => {
|
||||
}
|
||||
|
||||
const { body, blueprint_page_id } = req.body;
|
||||
console.log({ body, blueprint_page_id });
|
||||
// console.log({ body, blueprint_page_id });
|
||||
|
||||
const result = await createComment(blueprint_page_id, session.user, body);
|
||||
console.log(result);
|
||||
|
||||
res.status(200).json({ status: "Comment submitted" });
|
||||
} else if (req.method === "DELETE") {
|
||||
const { comment_id, comment_author } = req.body;
|
||||
|
||||
if (!session) {
|
||||
return res.status(401).json({ status: "Not authenticated" });
|
||||
}
|
||||
|
||||
if (session.user.role !== "moderator" && session.user.role !== "admin") {
|
||||
if (
|
||||
session.user.role !== "moderator" &&
|
||||
session.user.role !== "admin" &&
|
||||
session.user_id !== comment_author
|
||||
) {
|
||||
return res.status(401).json({ status: "Not authenticated" });
|
||||
}
|
||||
const { comment_id } = req.body;
|
||||
|
||||
await deleteComment(comment_id);
|
||||
res.status(200).json({ status: "Comment deleted" });
|
||||
} else {
|
||||
|
Loading…
x
Reference in New Issue
Block a user