This commit is contained in:
maaa 2023-07-08 19:04:16 +02:00
parent e2e6787181
commit 0f5e1f63d7
3 changed files with 30 additions and 7 deletions

View File

@ -3,6 +3,8 @@ for (let i = 0; i < posts.length; i++) {
let post = posts[i] let post = posts[i]
let commentButton = post.children["commentButton"] let commentButton = post.children["commentButton"]
let commentId = post.children["commentId"] let commentId = post.children["commentId"]
let commentBurgerDiv = post.children["commentBurgerDiv"]
let usernameElement = post.children["usernameElement"]
let commentDiv = post.children["commentDiv"] let commentDiv = post.children["commentDiv"]
let commentBox = commentDiv.children["commentBox"] let commentBox = commentDiv.children["commentBox"]
let commentSave = commentDiv.children["commentDivSave"] let commentSave = commentDiv.children["commentDivSave"]
@ -20,6 +22,16 @@ for (let i = 0; i < posts.length; i++) {
title = String(commentBox.value) title = String(commentBox.value)
id = String(commentId.innerHTML) 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", { fetch("/comment", {
method: "POST", method: "POST",
body: JSON.stringify({ body: JSON.stringify({
@ -30,8 +42,7 @@ for (let i = 0; i < posts.length; i++) {
"Content-Type": "application/json" "Content-Type": "application/json"
} }
}) })
.then((response) => response.json()) .then((response) => addPost())
.then((json) => console.log(json));
commentDiv.classList.add("hidden") commentDiv.classList.add("hidden")
}); });

View File

@ -39,21 +39,33 @@
<br><br> <br><br>
{% endif %} {% endif %}
{% endif %} {% endif %}
{% if userdata %}
<p class="hidden" id="usernameElement">{{ userdata.username }}</p>
{% endif %}
<img loading="lazy" src='{{ post["imageurl"] }}'> <img loading="lazy" src='{{ post["imageurl"] }}'>
<p class="text">{{ post["textstr"] }}</p> <p class="text">{{ post["textstr"] }}</p>
<div class="commentsdiv"> {% if getComments(post["id"]) | length > 0 %}
<div id="commentBurgerDiv" class="commentsdiv">
{% for comment in getComments(post["id"]) %} {% for comment in getComments(post["id"]) %}
<p>{{ getUser(comment["creator"])["username"] }}: {{ comment.textstr }}</p> <p>{{ getUser(comment["creator"])["username"] }}: {{ comment.textstr }}</p>
{% endfor %} {% endfor %}
</div> </div>
<p id="commentId" class="hidden">{{ post.id }}</p> {% else %}
{% if userdata %} <div id="commentBurgerDiv" class="hidden"></div>
<button id="commentButton" class="comment">comment</button>
{% endif %} {% endif %}
<p id="commentId" class="hidden">{{ post.id }}</p>
<button id="commentButton" class="comment">comment</button>
<div id="commentDiv" class="commentdiv hidden"> <div id="commentDiv" class="commentdiv hidden">
{% if userdata %}
<input id="commentBox" type="text" placeholder="content"> <input id="commentBox" type="text" placeholder="content">
<button id="commentDivSave">save</button> <button id="commentDivSave">save</button>
<button id="commentDivCancel">cancel</button> <button id="commentDivCancel">cancel</button>
{% else %}
<a href="/login">Log in</a>, or <a href="/signup">create an account</a> to <b>comment</b>, post, and more!
<input id="commentBox" class="hidden" type="text" placeholder="content">
<button id="commentDivSave" class="hidden">save</button>
<button id="commentDivCancel" class="hidden">cancel</button>
{% endif %}
</div> </div>
<script> <script>
function time2TimeAgo(ts) { function time2TimeAgo(ts) {

View File

@ -15,7 +15,7 @@
<a href="/">back</a> <a href="/">back</a>
<br><br> <br><br>
<h1>Create a burgercat account</h1> <h1>Create a burgercat account</h1>
<p>Create a burgercat acccount to create posts and more!</p> <p>Create a burgercat acccount to create posts, comment, and more!</p>
{% with messages = get_flashed_messages() %} {% with messages = get_flashed_messages() %}
{% if messages %} {% if messages %}
{% for message in messages %} {% for message in messages %}