diff --git a/TODO.txt b/TODO.txt new file mode 100644 index 00000000..136b99a6 --- /dev/null +++ b/TODO.txt @@ -0,0 +1,15 @@ +You'll see a short list of NHL teams, their scores, and buttons to increase their scores. +Right now, clicking on a button doesn't increase the score immediately, +but you need to refresh the page to see the change. The goal is to reflect +this change immediately on the front-end. Once that's done, we would also like +to sort the teams so that whenever there's a score change, the list would change +so that the teams are listed in non-increasing order of scores from top to bottom +(you don't need to sort them alphabetically when there is a tie). To do these, +you would need to make changes in both server.py file and scoreboard.js file. +When you're done, please send a pull request to this repository with your name and +uni in the comment. Thanks and good luck! + + +1. Update scores live on the website +2. Sort the teams in non-increasing order from top to bottom (no tiebreaking necessary for teams with the same score) + diff --git a/server.py b/server.py index 372a266c..ffd4d025 100644 --- a/server.py +++ b/server.py @@ -50,6 +50,9 @@ def increase_score(): for team in scoreboard: if team["id"] == team_id: team["score"] += 1 + break + + scoreboard.sort(key = lambda team: team["score"], reverse = True) return jsonify(scoreboard=scoreboard) diff --git a/static/scoreboard.js b/static/scoreboard.js index 34ce2009..f48d7c1c 100644 --- a/static/scoreboard.js +++ b/static/scoreboard.js @@ -32,7 +32,7 @@ function increase_score(id){ contentType: "application/json; charset=utf-8", data : JSON.stringify(team_id), success: function(result){ - + display_scoreboard(result.scoreboard); }, error: function(request, status, error){ console.log("Error");