feat: add post comments

This commit is contained in:
ktyl 2024-07-13 01:45:55 +01:00
parent 1bf1395ef6
commit cd17ad53ad
1 changed files with 17 additions and 1 deletions

18
main.js
View File

@ -69,11 +69,27 @@ class Post {
postElem.appendChild(profileLinkElem); postElem.appendChild(profileLinkElem);
// TODO: add content to the post
const contentElem = document.createElement("p"); const contentElem = document.createElement("p");
contentElem.innerHTML = this.content; contentElem.innerHTML = this.content;
postElem.appendChild(contentElem); postElem.appendChild(contentElem);
// add a random number of comments to the post
const numComments = Math.random() * 5;
for (let i = 0; i < numComments; i++) {
const commentElem = document.createElement("div");
commentElem.style.backgroundColor = getRandomColor();
const commentUserElem = document.createElement("h2");
commentUserElem.innerHTML = getUsername();
commentElem.appendChild(commentUserElem);
const commentContentElem = document.createElement("p");
commentContentElem.innerHTML = `comment ${i}`;
commentElem.appendChild(commentContentElem);
postElem.appendChild(commentElem);
}
return postElem; return postElem;
} }
} }