Skip to content

Commit 768c009

Browse files
committed
add post comments to single page
1 parent ccea826 commit 768c009

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

public/css/style.css

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,20 @@ img {
2424
margin: 30px 0;
2525
}
2626

27+
28+
.comment {
29+
margin: 15px 0;
30+
}
31+
.comment-level-1 {
32+
padding-left: 15px;
33+
}
34+
.comment-level-2 {
35+
padding-left: 30px;
36+
}
37+
.comment-level-3 {
38+
padding-left: 45px;
39+
}
40+
2741
input, label, textarea, button {
2842
/*margin: 15px 0;
2943
width: 100%;

public/js/main.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ function getPostAndComments(url) {
136136
}))
137137
}
138138
appendSinglePost(resultsByDepth[0][0], users)
139+
appendComments(resultsByDepth)
139140

140141
})
141142
}
@@ -174,6 +175,51 @@ function appendSinglePost(post, users){
174175
$('main').append(header + html)
175176
}
176177

178+
function appendComments(posts){
179+
$('main').append('<div class="comments"></div>')
180+
181+
posts.forEach( (postsAtDepth, i, arr) => {
182+
postsAtDepth.forEach( (post, i, arr) => {
183+
let template = createCommentTemplate(post)
184+
if ( post.depth === 1 ) {
185+
$('.comments').prepend( template)
186+
} else if ( post.depth > 1) {
187+
var permlink = post.parent_permlink
188+
$('.' + permlink ).append( template)
189+
}
190+
})
191+
})
192+
}
193+
194+
195+
createCommentTemplate = (post) => {
196+
var permlink = post.parent_permlink
197+
var html = converter.makeHtml(post.body)
198+
var voteMessage = (post.votes > 1 || post.votes == 0 )? 'votes' : 'vote'
199+
var voteValue = (post.value > 0) ? '</span> <span>|</span> <span>$' + post.value + '</span><span>': ''
200+
var template = `
201+
<div data-post-id="${post.id}"
202+
data-permlink="${post.permlink}"
203+
data-author="${post.author}"
204+
data-title="${post.title}"
205+
data-post-depth="${post.depth}"
206+
class="comment comment-level-${post.depth} ${post.permlink}">
207+
<h4>
208+
<a href="https://steemit.com/@${post.author}" target="_blank">@${post.author}</a>
209+
<span> &middot; </span> <span> ${ post.created } </span>
210+
</h4>
211+
<p>${ html }</p>
212+
<div class="meta">
213+
<span class="upvote">Upvote</span>
214+
<span class="sc-item__divider">|</span>
215+
<span class="sc-item__votecount">${post.votes} ${voteMessage} </span>
216+
<span class="sc-item__divider">|</span>
217+
<span class="sc-item__reply">Reply</span>
218+
</div>
219+
</div>`
220+
return template;
221+
}
222+
177223
// ----------------------------------------------------
178224

179225
if ($('main').hasClass('feed') ) {

0 commit comments

Comments
 (0)