myheats

Live heats, scoring and leaderboard for sport events
git clone https://git.in0rdr.ch/myheats.git
Log | Files | Refs | Pull requests | README | LICENSE

commit 5b54a388e20db1f7b21739b279068e1d8236a920
parent c641d7154dbc7bddee80c28cb0efc7dc81c44782
Author: Andreas Gruhler <andreas.gruhler@adfinis.com>
Date:   Sat, 28 Sep 2024 13:27:44 +0200

feat(leaderboard): move ws close/open from effect

Diffstat:
Msrc/frontend/Leaderboard.jsx | 21+++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/src/frontend/Leaderboard.jsx b/src/frontend/Leaderboard.jsx @@ -12,6 +12,17 @@ const ws_port = import.meta.env.VITE_WS_PORT let socket = new WebSocket(`${ws_uri}:${ws_port}/v1/leaderboard`); console.info("Attached to server websocket"); +socket.onclose = async function(event) { + console.info("Server removed us from client list, reattaching socket"); + socket = new WebSocket(`${ws_uri}:${ws_port}/v1/leaderboard`); +} +socket.onopen = function (event) { + // subscribe to scoring from judges when socket is opened + socket.send(JSON.stringify({ + method: "watchScores", + })) +} + export async function addAthleteToHeat(athlete, heat) { const res = await fetch(`${api_uri}:${api_port}/v1/leaderboard/addAthleteToHeat`, { method: 'POST', @@ -318,16 +329,6 @@ function Leaderboard({session}) { const scoreSummary = await getScoreSummary(heatSelection.map(h => h.value)) setLeaderboard(scoreSummary) } - socket.onclose = async function(event) { - console.info("Server removed us from client list, reattaching socket"); - socket = new WebSocket(`${ws_uri}:${ws_port}/v1/leaderboard`); - } - socket.onopen = function (event) { - // subscribe to scoring from judges when socket is opened - socket.send(JSON.stringify({ - method: "watchScores", - })) - } setLoading(false) })(); }, [heatSelection]);