Hide upvote arrow on news page if already upvoted. Make it disappear on upvote

This commit is contained in:
MrRenter
2015-03-17 02:06:58 -04:00
parent b7dd72f3a3
commit c9970c1725
3 changed files with 18 additions and 5 deletions

View File

@ -137,7 +137,16 @@ exports.returnIndividualStory = function(req, res, next) {
return res.redirect('../stories/' + dashedNameFull); return res.redirect('../stories/' + dashedNameFull);
} }
res.render('stories/index', {
var votedObj = story.upVotes.filter(function(a){
return a['upVotedByUsername'] === req.user['profile']['username'];
})
var userVoted = false;
if (votedObj.length > 0){
userVoted = true;
}
res.render('stories/index', {
title: story.headline, title: story.headline,
link: story.link, link: story.link,
author: story.author, author: story.author,
@ -150,7 +159,8 @@ exports.returnIndividualStory = function(req, res, next) {
timeAgo: moment(story.timePosted).fromNow(), timeAgo: moment(story.timePosted).fromNow(),
image: story.image, image: story.image,
page: 'show', page: 'show',
storyMetaDescription: story.metaDescription storyMetaDescription: story.metaDescription,
hasUserVoted: userVoted
}); });
}); });
}; };

View File

@ -120,7 +120,8 @@ $(document).ready(function() {
}); });
var upvoteHandler = function () { var upvoteHandler = function () {
var _id = storyId; $(".ion-arrow-up-b").hide();
var _id = storyId;
$('#upvote').unbind('click'); $('#upvote').unbind('click');
var alreadyUpvoted = false; var alreadyUpvoted = false;
for (var i = 0; i < upVotes.length; i++) { for (var i = 0; i < upVotes.length; i++) {

View File

@ -6,6 +6,7 @@
var upVotes = !{JSON.stringify(upVotes)}; var upVotes = !{JSON.stringify(upVotes)};
var user = !{JSON.stringify(user)}; var user = !{JSON.stringify(user)};
var image = !{JSON.stringify(image)}; var image = !{JSON.stringify(image)};
var hasUserVoted = !{JSON.stringify(hasUserVoted)};
.spacer .spacer
h3.row.col-xs-12 h3.row.col-xs-12
@ -13,8 +14,9 @@
.col-xs-3.col-sm-1.text-center .col-xs-3.col-sm-1.text-center
.row.negative-5 .row.negative-5
.col-xs-12.big-ion-up-arrow .col-xs-12.big-ion-up-arrow
a#upvote if !hasUserVoted
i.ion-arrow-up-b a#upvote
i.ion-arrow-up-b
h3.story-up-votes h3.story-up-votes
span#storyRank= rank span#storyRank= rank
.col-xs-2.col-sm-1 .col-xs-2.col-sm-1