From c9970c17253477ac1a5cd5f63afd6260e77f0a76 Mon Sep 17 00:00:00 2001 From: MrRenter Date: Tue, 17 Mar 2015 02:06:58 -0400 Subject: [PATCH] Hide upvote arrow on news page if already upvoted. Make it disappear on upvote --- controllers/story.js | 14 ++++++++++++-- public/js/main.js | 3 ++- views/stories/show.jade | 6 ++++-- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/controllers/story.js b/controllers/story.js index fea8f00a42..97f31d16cd 100644 --- a/controllers/story.js +++ b/controllers/story.js @@ -137,7 +137,16 @@ exports.returnIndividualStory = function(req, res, next) { 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, link: story.link, author: story.author, @@ -150,7 +159,8 @@ exports.returnIndividualStory = function(req, res, next) { timeAgo: moment(story.timePosted).fromNow(), image: story.image, page: 'show', - storyMetaDescription: story.metaDescription + storyMetaDescription: story.metaDescription, + hasUserVoted: userVoted }); }); }; diff --git a/public/js/main.js b/public/js/main.js index 8170c1c297..5979fd88c6 100644 --- a/public/js/main.js +++ b/public/js/main.js @@ -120,7 +120,8 @@ $(document).ready(function() { }); var upvoteHandler = function () { - var _id = storyId; + $(".ion-arrow-up-b").hide(); + var _id = storyId; $('#upvote').unbind('click'); var alreadyUpvoted = false; for (var i = 0; i < upVotes.length; i++) { diff --git a/views/stories/show.jade b/views/stories/show.jade index 2d02ff0077..848f5cc5ac 100644 --- a/views/stories/show.jade +++ b/views/stories/show.jade @@ -6,6 +6,7 @@ var upVotes = !{JSON.stringify(upVotes)}; var user = !{JSON.stringify(user)}; var image = !{JSON.stringify(image)}; + var hasUserVoted = !{JSON.stringify(hasUserVoted)}; .spacer h3.row.col-xs-12 @@ -13,8 +14,9 @@ .col-xs-3.col-sm-1.text-center .row.negative-5 .col-xs-12.big-ion-up-arrow - a#upvote - i.ion-arrow-up-b + if !hasUserVoted + a#upvote + i.ion-arrow-up-b h3.story-up-votes span#storyRank= rank .col-xs-2.col-sm-1