Skip to content

Commit b7459c4

Browse files
committed
add post comment
1 parent 5466caa commit b7459c4

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

public/js/main.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,13 @@ function appendSinglePost(post, users){
204204
<input type="hidden" name="permlink" value="${post.permlink}">
205205
<input type="submit" class="vote" value="Vote">
206206
</form>`
207-
$('main').append(header + html + voteButton)
207+
let commentBox = `
208+
<div>
209+
<textarea class="comment-message" rows="5"></textarea>
210+
<span class="send-comment" data-parent="${post.author}" data-parent-permlink="${post.permlink}" data-parent-title="${post.title}">Post Comment</span>
211+
</div>
212+
`
213+
$('main').append(header + html + voteButton + commentBox)
208214
}
209215

210216
function appendComments(posts){
@@ -374,5 +380,22 @@ $('main').on('click', '.vote',(e) => {
374380
$('<span>Voted!</span>').insertAfter($voteButton)
375381
}
376382
})
383+
})
384+
385+
$('main').on('click', '.send-comment', (e) => {
386+
let $comment = $(e.currentTarget)
377387

388+
$.post({
389+
url: `/post/comment`,
390+
dataType: 'json',
391+
data: {
392+
parentAuthor: $comment.data('parent'),
393+
parentPermlink: $comment.data('parent-permlink'),
394+
message: $('.comment-message').val(),
395+
parentTitle: $comment.data('parent-title')
396+
}
397+
}, (response) => {
398+
console.log(response)
399+
$(`<p>${response.msg}</p>`).insertAfter($comment)
400+
})
378401
})

routes/post.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,25 @@ router.post('/vote', util.isAuthenticated, (req, res) => {
5050
});
5151
})
5252

53+
54+
router.post('/comment', util.isAuthenticated, (req, res) => {
55+
56+
let author = req.session.steemconnect.name
57+
let permlink = req.body.parentPermlink + '-' + util.urlString()
58+
let title = 'RE: ' + req.body.parentTitle
59+
let body = req.body.message
60+
let parentAuthor = req.body.parentAuthor
61+
let parentPermlink = req.body.parentPermlink
62+
steem.comment(parentAuthor, parentPermlink, author, permlink, title, body, '', (err, steemResponse) => {
63+
if (err) {
64+
res.json({ error: err.error_description })
65+
} else {
66+
res.json({
67+
msg: 'Posted To Steem Network',
68+
res: steemResponse
69+
})
70+
}
71+
});
72+
});
73+
5374
module.exports = router;

0 commit comments

Comments
 (0)