From 143f893271f757c0aa555fe2af6b9f57ec388a06 Mon Sep 17 00:00:00 2001 From: Tung Do Date: Tue, 28 Jul 2026 12:51:03 +0700 Subject: [PATCH] Update scoreboard immediately and sort by score - server.py: sort scoreboard in non-increasing order of score on page load and after each score increase before returning JSON - scoreboard.js: re-render the board in the AJAX success callback so score changes appear immediately without a page refresh - add .gitignore for __pycache__ Name: Tung Do UNI: tnd2125 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .gitignore | 1 + server.py | 3 +++ static/scoreboard.js | 2 +- 3 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..c18dd8d8 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +__pycache__/ diff --git a/server.py b/server.py index 372a266c..70cf6229 100644 --- a/server.py +++ b/server.py @@ -38,6 +38,7 @@ @app.route('/') def show_scoreboard(): + scoreboard.sort(key=lambda team: team["score"], reverse=True) return render_template('scoreboard.html', scoreboard = scoreboard) @app.route('/increase_score', methods=['GET', 'POST']) @@ -51,6 +52,8 @@ def increase_score(): if team["id"] == team_id: team["score"] += 1 + 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");