2023-07-08 17:00:32 +01:00
|
|
|
const posts = document.getElementsByClassName("post")
|
|
|
|
for (let i = 0; i < posts.length; i++) {
|
|
|
|
let post = posts[i]
|
|
|
|
let commentButton = post.children["commentButton"]
|
|
|
|
let commentId = post.children["commentId"]
|
2023-07-08 18:04:16 +01:00
|
|
|
let commentBurgerDiv = post.children["commentBurgerDiv"]
|
|
|
|
let usernameElement = post.children["usernameElement"]
|
2023-07-08 17:00:32 +01:00
|
|
|
let commentDiv = post.children["commentDiv"]
|
|
|
|
let commentBox = commentDiv.children["commentBox"]
|
|
|
|
let commentSave = commentDiv.children["commentDivSave"]
|
|
|
|
let commentCancel = commentDiv.children["commentDivCancel"]
|
|
|
|
|
|
|
|
commentButton.addEventListener("click", (e) => {
|
|
|
|
commentDiv.classList.remove("hidden")
|
|
|
|
commentBox.value = ""
|
|
|
|
});
|
|
|
|
commentCancel.addEventListener("click", (e) => {
|
|
|
|
commentDiv.classList.add("hidden")
|
|
|
|
});
|
|
|
|
commentSave.addEventListener("click", (e) => {
|
|
|
|
console.log(commentId.innerHTML)
|
|
|
|
title = String(commentBox.value)
|
|
|
|
id = String(commentId.innerHTML)
|
|
|
|
|
2023-07-09 01:16:04 +01:00
|
|
|
commentDiv.classList.add("hidden")
|
|
|
|
commentBurgerDiv.classList.remove("hidden")
|
2023-07-08 18:04:16 +01:00
|
|
|
|
2023-07-09 01:16:04 +01:00
|
|
|
let para = document.createElement("p");
|
|
|
|
const node = document.createTextNode(usernameElement.innerHTML + ": " + title);
|
|
|
|
para.appendChild(node)
|
|
|
|
commentBurgerDiv.append(para)
|
2023-07-08 18:04:16 +01:00
|
|
|
|
2023-07-08 23:44:53 +01:00
|
|
|
fetch("/api/comment", {
|
2023-07-08 17:00:32 +01:00
|
|
|
method: "POST",
|
|
|
|
body: JSON.stringify({
|
|
|
|
id: id,
|
|
|
|
title: title,
|
|
|
|
}),
|
|
|
|
headers: {
|
|
|
|
"Content-Type": "application/json"
|
|
|
|
}
|
|
|
|
})
|
|
|
|
});
|
|
|
|
}
|