From 0858cbe89296d852fa46f944e053d85b97a4af92 Mon Sep 17 00:00:00 2001 From: Asger Geel Weirsoee Date: Sat, 28 Feb 2026 01:16:15 +0100 Subject: [PATCH] ui(host): guard start round until 3 players in lobby --- lobby/templates/lobby/host_screen.html | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lobby/templates/lobby/host_screen.html b/lobby/templates/lobby/host_screen.html index 25df4d6..971a619 100644 --- a/lobby/templates/lobby/host_screen.html +++ b/lobby/templates/lobby/host_screen.html @@ -6,7 +6,9 @@ - + +

Kræver mindst 3 spillere i lobbyen.

+

Spillere i session: ukendt

@@ -20,15 +22,18 @@ function csrf(){var m=document.cookie.match(/csrftoken=([^;]+)/);return m?m[1]:"";} function code(){return document.getElementById("code").value.trim().toUpperCase();} function rq(){return document.getElementById("roundQuestionId").value.trim();} -async function api(path,method,payload){var o={method:method||"GET",headers:{"Accept":"application/json"}};if(payload!==null){o.headers["Content-Type"]="application/json";o.headers["X-CSRFToken"]=csrf();o.body=JSON.stringify(payload);}var r=await fetch(path,o);var d=await r.json().catch(function(){return {};});document.getElementById("out").textContent=JSON.stringify({status:r.status,data:d},null,2);if(d.session&&d.session.code){document.getElementById("code").value=d.session.code;}if(d.round_question&&d.round_question.id){document.getElementById("roundQuestionId").value=d.round_question.id;}return d;} +function syncStartRoundGuard(data){var btn=document.getElementById("startRoundBtn");var hint=document.getElementById("startRoundHint");var status=document.getElementById("playerCountStatus");if(!btn||!hint||!status){return;}var count=(data&&data.session&&typeof data.session.players_count==="number")?data.session.players_count:null;if(count===null){btn.disabled=true;status.textContent="Spillere i session: ukendt";hint.textContent="Opdatér session-status for at validere min. 3 spillere.";return;}status.textContent="Spillere i session: "+count;if(count<3){btn.disabled=true;hint.textContent="Mangler spillere: kræver mindst 3 for at starte runde.";return;}btn.disabled=false;hint.textContent="Klar: nok spillere til at starte runde.";} +async function api(path,method,payload){var o={method:method||"GET",headers:{"Accept":"application/json"}};if(payload!==null){o.headers["Content-Type"]="application/json";o.headers["X-CSRFToken"]=csrf();o.body=JSON.stringify(payload);}var r=await fetch(path,o);var d=await r.json().catch(function(){return {};});document.getElementById("out").textContent=JSON.stringify({status:r.status,data:d},null,2);if(d.session&&d.session.code){document.getElementById("code").value=d.session.code;}if(d.round_question&&d.round_question.id){document.getElementById("roundQuestionId").value=d.round_question.id;}syncStartRoundGuard(d);return d;} function createSession(){return api("/lobby/sessions/create","POST",{});} function sessionDetail(){return api("/lobby/sessions/"+code(),"GET",null);} -function startRound(){return api("/lobby/sessions/"+code()+"/rounds/start","POST",{category_slug:document.getElementById("category").value});} +function startRound(){if(document.getElementById("startRoundBtn").disabled){return Promise.resolve({error:"not_enough_players_client_guard"});}return api("/lobby/sessions/"+code()+"/rounds/start","POST",{category_slug:document.getElementById("category").value});} function showQuestion(){return api("/lobby/sessions/"+code()+"/questions/show","POST",{});} function mixAnswers(){return api("/lobby/sessions/"+code()+"/questions/"+rq()+"/answers/mix","POST",{});} function calcScores(){return api("/lobby/sessions/"+code()+"/questions/"+rq()+"/scores/calculate","POST",{});} function showScoreboard(){return api("/lobby/sessions/"+code()+"/scoreboard","GET",null);} function nextRound(){return api("/lobby/sessions/"+code()+"/rounds/next","POST",{});} function finishGame(){return api("/lobby/sessions/"+code()+"/finish","POST",{});} +document.getElementById("code").addEventListener("input",function(){syncStartRoundGuard(null);}); +syncStartRoundGuard(null); -- 2.39.5