From 910bab2c00f8bfb17334c0a033958b08d2deb308 Mon Sep 17 00:00:00 2001 From: Taha Lahlou Date: Sat, 13 Dec 2025 20:24:49 -0500 Subject: [PATCH] Update scoreboard instantly and sort by score --- static/scoreboard.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/static/scoreboard.js b/static/scoreboard.js index 34ce2009..fdd8519e 100644 --- a/static/scoreboard.js +++ b/static/scoreboard.js @@ -24,7 +24,7 @@ function addTeamView(id, name, score){ } function increase_score(id){ - var team_id = {"id": id} + var team_id = {"id": id}; $.ajax({ type: "POST", url: "increase_score", @@ -32,8 +32,18 @@ function increase_score(id){ contentType: "application/json; charset=utf-8", data : JSON.stringify(team_id), success: function(result){ - - }, + // result might be {scoreboard: [...]} OR just [...] + scoreboard = result.scoreboard ? result.scoreboard : result; + + // sort high score -> low score + scoreboard.sort(function(a, b){ + return b.score - a.score; + }); + + // re-render immediately + display_scoreboard(scoreboard); + }, + error: function(request, status, error){ console.log("Error"); console.log(request)