Skip to content
This repository

Incrementing up/down vote counts after voting #56

Closed
wants to merge 7 commits into from

4 participants

Steve Gattuso Rick Waldron Salvatore Sanfilippo
Steve Gattuso

Adds some code that increments the up/down vote counts below the title upon a successful vote.

Rick Waldron

This adds two additional calls for the same $("#" + news_id) context element to both logic paths. The context selection and .upvote / .downvote filters should be cached as references

public/js/app.js
@@ -120,6 +120,7 @@ $(document).ready(function() {
120 120 success: function(reply) {
121 121 var r = jQuery.parseJSON(reply);
122 122 if (r.status == "ok") {
  123 + $('#'+news_id+' .upvotes').text(parseInt($('#'+news_id+' .upvotes').text()) + 1)
3
Rick Waldron
rwaldron added a note

These parseInt calls are missing the radix argument.

Salvatore Sanfilippo Owner
antirez added a note

Doesn't this only counts if your integers have additional zeroes on the left?

Rick Waldron
rwaldron added a note

It's just responsible programming to include the argument

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
public/js/app.js
@@ -145,6 +146,7 @@ $(document).ready(function() {
145 146 success: function(reply) {
146 147 var r = jQuery.parseJSON(reply);
147 148 if (r.status == "ok") {
  149 + $('#'+news_id+' .downvotes').text(parseInt($('#'+news_id+' .downvotes').text()) + 1)
1
Rick Waldron
rwaldron added a note

Same as above... these parseInt calls are missing the radix argument.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Steve Gattuso

I believe I fixed the problems. Let me know if anything else seems off.

public/js/app.js
@@ -145,6 +147,8 @@ $(document).ready(function() {
145 147 success: function(reply) {
146 148 var r = jQuery.parseJSON(reply);
147 149 if (r.status == "ok") {
  150 + var vote_count = $('#'+news_id+' .downvotes')
1
Rick Waldron
rwaldron added a note

The rest of the code is using double quotes, but you've used single quotes?

Also, you're missing semi-colons here and below.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

+1 on this. Always thought this was needed on HN.

Salvatore Sanfilippo
Owner

probably this can't be merged now that I merged the changes to make the layout using only HTML5 standard tags?

Steve Gattuso
Salvatore Sanfilippo
Owner

not sure, after merging the latest pull requests not even normal voting works ;) Fixing this problem and trying if there are conflicts. Well there are not conflicts but since the markup changed not sure if this is going to wok.

Steve Gattuso
Salvatore Sanfilippo
Owner

Thanks maybe I'll be able to test it as well today. Btw voting fixed with last commit.

Frederic Cambus fcambus closed this pull request from a commit
Frederic Cambus fcambus Incrementing up/down vote counts after voting news (Close #56)
Pull request #56 could not be merged directly, as the markup and the
JavaScript code changed. Thanks @stevenleeg.
b65b27b
Frederic Cambus fcambus closed this in b65b27b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.

Showing 2 changed files with 8 additions and 1 deletion. Show diff stats Hide diff stats

  1. +4 1 app.rb
  2. +4 0 public/js/app.js
5 app.rb
@@ -964,7 +964,10 @@ def news_to_html(news)
964 964 "▼"
965 965 }+
966 966 H.p {
967   - "#{news["up"]} up and #{news["down"]} down, posted by "+
  967 + H.span(:class => :upvotes) { news['up'] } +
  968 + " up and " +
  969 + H.span(:class => :downvotes) { news['down'] } +
  970 + " down, posted by " +
968 971 H.username {
969 972 H.a(:href=>"/user/"+H.urlencode(news["username"])) {
970 973 H.entities news["username"]
4 public/js/app.js
@@ -120,6 +120,8 @@ $(document).ready(function() {
120 120 success: function(reply) {
121 121 var r = jQuery.parseJSON(reply);
122 122 if (r.status == "ok") {
  123 + var vote_count = $('#'+news_id+' .upvotes');
  124 + vote_count.text(parseInt(vote_count.text(), 10) + 1);
123 125 n = $("#"+news_id)[0];
124 126 n.children[0].setAttribute("class","voted");
125 127 n.children[3].setAttribute("class","disabled");
@@ -145,6 +147,8 @@ $(document).ready(function() {
145 147 success: function(reply) {
146 148 var r = jQuery.parseJSON(reply);
147 149 if (r.status == "ok") {
  150 + var vote_count = $("#"+news_id+" .downvotes");
  151 + vote_count.text(parseInt(vote_count.text(), 10) + 1);
148 152 n = $("#"+news_id)[0];
149 153 n.children[0].setAttribute("class","disabled");
150 154 n.children[3].setAttribute("class","voted");

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.