From 0f5e1f63d7f9c5a3c35101485ad350039b0be190 Mon Sep 17 00:00:00 2001 From: maaa Date: Sat, 8 Jul 2023 19:04:16 +0200 Subject: [PATCH] changes --- static/js/main.js | 15 +++++++++++++-- templates/main.html | 20 ++++++++++++++++---- templates/signup.html | 2 +- 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/static/js/main.js b/static/js/main.js index b16b31f..7900d80 100644 --- a/static/js/main.js +++ b/static/js/main.js @@ -3,6 +3,8 @@ for (let i = 0; i < posts.length; i++) { let post = posts[i] let commentButton = post.children["commentButton"] let commentId = post.children["commentId"] + let commentBurgerDiv = post.children["commentBurgerDiv"] + let usernameElement = post.children["usernameElement"] let commentDiv = post.children["commentDiv"] let commentBox = commentDiv.children["commentBox"] let commentSave = commentDiv.children["commentDivSave"] @@ -20,6 +22,16 @@ for (let i = 0; i < posts.length; i++) { title = String(commentBox.value) id = String(commentId.innerHTML) + + function addPost() { + console.log("fart") + + let para = document.createElement("p"); + const node = document.createTextNode(usernameElement.innerHTML + ": " + title); + para.appendChild(node) + commentBurgerDiv.append(para) + } + fetch("/comment", { method: "POST", body: JSON.stringify({ @@ -30,8 +42,7 @@ for (let i = 0; i < posts.length; i++) { "Content-Type": "application/json" } }) - .then((response) => response.json()) - .then((json) => console.log(json)); + .then((response) => addPost()) commentDiv.classList.add("hidden") }); diff --git a/templates/main.html b/templates/main.html index d02dd55..1d854b5 100644 --- a/templates/main.html +++ b/templates/main.html @@ -39,21 +39,33 @@

{% endif %} {% endif %} + {% if userdata %} + + {% endif %}

{{ post["textstr"] }}

-
+ {% if getComments(post["id"]) | length > 0 %} +
{% for comment in getComments(post["id"]) %}

{{ getUser(comment["creator"])["username"] }}: {{ comment.textstr }}

{% endfor %}
- - {% if userdata %} - + {% else %} + {% endif %} + +