diff --git a/server.py b/server.py index 372a266c..420ab54a 100644 --- a/server.py +++ b/server.py @@ -47,9 +47,17 @@ def increase_score(): json_data = request.get_json() team_id = json_data["id"] + index = 0 for team in scoreboard: if team["id"] == team_id: team["score"] += 1 + if index != 0: + if scoreboard[index-1]["score"] < team["score"]: + team_updated = scoreboard.pop(index) + placeholder = scoreboard.pop(index-1) + scoreboard.insert(index - 1, team_updated) + scoreboard.insert(index, placeholder) + index += 1 return jsonify(scoreboard=scoreboard) diff --git a/static/scoreboard.js b/static/scoreboard.js index 34ce2009..8f2aa129 100644 --- a/static/scoreboard.js +++ b/static/scoreboard.js @@ -32,7 +32,8 @@ function increase_score(id){ contentType: "application/json; charset=utf-8", data : JSON.stringify(team_id), success: function(result){ - + console.log(result) + display_scoreboard(result.scoreboard); }, error: function(request, status, error){ console.log("Error");