From bb3fc92300e13cf00329d45b5e651ecfc4a813cd Mon Sep 17 00:00:00 2001 From: Siwakorn Komolhiran Date: Sat, 24 Jan 2026 17:14:10 -0500 Subject: [PATCH] Reflect score change on frontend and reorder teams descendingly --- server.py | 2 ++ static/scoreboard.js | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/server.py b/server.py index 372a266c..e08bdb03 100644 --- a/server.py +++ b/server.py @@ -51,6 +51,8 @@ def increase_score(): if team["id"] == team_id: team["score"] += 1 + # Sort teams by score in descending order for frontend + scoreboard.sort(key=lambda x: x["score"], reverse=True) return jsonify(scoreboard=scoreboard) diff --git a/static/scoreboard.js b/static/scoreboard.js index 34ce2009..22a98eae 100644 --- a/static/scoreboard.js +++ b/static/scoreboard.js @@ -32,7 +32,12 @@ function increase_score(id){ contentType: "application/json; charset=utf-8", data : JSON.stringify(team_id), success: function(result){ - + // Sort teams by score in descending order + var sorted = result.scoreboard.sort(function(a, b) { + return b.score - a.score; + }); + // Re-render the scoreboard immediately + display_scoreboard(sorted); }, error: function(request, status, error){ console.log("Error");