Skip to content

Commit 5466caa

Browse files
committed
add vote from feed + single page + vote comments
1 parent aa6e4cc commit 5466caa

File tree

3 files changed

+42
-6
lines changed

3 files changed

+42
-6
lines changed

public/css/style.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ img {
3939
padding-left: 45px;
4040
}
4141

42+
.meta form {
43+
display: inline-block;
44+
}
4245
input, label, textarea, button {
4346
/*margin: 15px 0;
4447
width: 100%;

public/js/main.js

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,17 @@ function displayContent(result, initial){
8383
}
8484

8585
let itemTemplate = `
86-
<div class="item " data-url="${post.url}" data-permlink="${ post.permlink }">
86+
<div class="item " data-post-id="${post.id}" data-url="${post.url}" data-permlink="${ post.permlink }">
8787
<img class="item__image " src="https://steemitimages.com/520x520/${image}" onerror="">
8888
<div class="item__author">
8989
<a href="${post.url}"><h2>${post.title}</h2></a>
9090
<a href="@${post.author}"><span>@${post.author}</span></a>
91+
<form method="post">
92+
<input type="hidden" name="postId" value="${post.id}">
93+
<input type="hidden" name="author" value="${post.author}">
94+
<input type="hidden" name="permlink" value="${post.permlink}">
95+
<input type="submit" class="vote" value="Vote">
96+
</form>
9197
</div>
9298
</div>
9399
`
@@ -191,7 +197,14 @@ function appendSinglePost(post, users){
191197
${tags}
192198
<h1 class="title">${post.title}</h1>
193199
`
194-
$('main').append(header + html)
200+
let voteButton = `
201+
<form method="post">
202+
<input type="hidden" name="postId" value="${post.id}">
203+
<input type="hidden" name="author" value="${post.author}">
204+
<input type="hidden" name="permlink" value="${post.permlink}">
205+
<input type="submit" class="vote" value="Vote">
206+
</form>`
207+
$('main').append(header + html + voteButton)
195208
}
196209

197210
function appendComments(posts){
@@ -229,7 +242,12 @@ createCommentTemplate = (post) => {
229242
</h4>
230243
<p>${ html }</p>
231244
<div class="meta">
232-
<span class="upvote">Upvote</span>
245+
<form method="post">
246+
<input type="hidden" name="postId" value="${post.id}">
247+
<input type="hidden" name="author" value="${post.author}">
248+
<input type="hidden" name="permlink" value="${post.permlink}">
249+
<input type="submit" class="vote" value="Vote">
250+
</form>
233251
<span class="sc-item__divider">|</span>
234252
<span class="sc-item__votecount">${post.votes} ${voteMessage} </span>
235253
<span class="sc-item__divider">|</span>
@@ -340,3 +358,21 @@ if ($('main').hasClass('profile') ) {
340358
})
341359
getBlog(username)
342360
}
361+
362+
363+
$('main').on('click', '.vote',(e) => {
364+
let $voteButton = $(e.currentTarget)
365+
e.preventDefault()
366+
$.post({
367+
url: '/post/vote',
368+
dataType: 'json',
369+
data: $(e.currentTarget).parent().serialize()
370+
}, (response) => {
371+
if (response.error) {
372+
$(`<span>${response.error.error_description}</span>`).insertAfter($voteButton)
373+
} else {
374+
$('<span>Voted!</span>').insertAfter($voteButton)
375+
}
376+
})
377+
378+
})

views/single.pug

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,3 @@ block content
44
include partials/nav
55

66
main.single(data-username=`${username}` data-permlink=`${permlink}` data-category=`${category}`)
7-
h1 Profile
8-
h2 #{username}
9-
h2 #{permlink}

0 commit comments

Comments
 (0)