From 27116777b10f692645b03da3fad73f4d27231ad9 Mon Sep 17 00:00:00 2001 From: Simay Cural Date: Sun, 8 Dec 2024 13:25:30 -0500 Subject: [PATCH] updated sorting and refreshing --- static/scoreboard.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/static/scoreboard.js b/static/scoreboard.js index 34ce2009..f7540c08 100644 --- a/static/scoreboard.js +++ b/static/scoreboard.js @@ -32,7 +32,25 @@ function increase_score(id){ contentType: "application/json; charset=utf-8", data : JSON.stringify(team_id), success: function(result){ + result.scoreboard.forEach(function(team) { + var teamRow = $('div.row').filter(function() { + return $(this).find('div.col-md-5').text() === team.name; + }); + teamRow.find('div.col-md-2').first().text(team.score); + }); + + var rows = $('div.row').get(); + rows.sort(function(a, b) { + var scoreA = parseInt($(a).find('div.col-md-2').first().text()); + var scoreB = parseInt($(b).find('div.col-md-2').first().text()); + return scoreB - scoreA; + }); + + var teamsContainer = $("#teams"); + rows.forEach(function(row) { + teamsContainer.append(row); + }); }, error: function(request, status, error){ console.log("Error");