-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrender.js
33 lines (22 loc) · 951 Bytes
/
render.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
const Renderer = function () {
const _renderComment = function (comment, div) {
const commentDiv = `<div data-id=${comment.id} class= comments>${comment.text}<div class=delete-comment>X</div></div>`
div.append(commentDiv)
}
const _renderPost = function (post, div) {
const postDiv = $(`<div data-id=${post.id} class=post > <div class=post-text>${post.text} <div class=delete>Delete post</div></div></div>`)
for (const c of post.comments) {
_renderComment(c, postDiv)
}
const commentBtn = $("<input type='text' placeholder='comment' class=postComment> <button class=comment >post comment</button>")
postDiv.append(commentBtn)
div.append(postDiv)
}
const renderPosts = function (posts) {
$("#posts").empty()
for (const p of posts) {
_renderPost(p, $("#posts"))
}
}
return { renderPosts }
}