diff --git a/lobby/templates/lobby/player_screen.html b/lobby/templates/lobby/player_screen.html index 9705e84..68ce98f 100644 --- a/lobby/templates/lobby/player_screen.html +++ b/lobby/templates/lobby/player_screen.html @@ -1,5 +1,11 @@ -WPP Player +WPP Player + +

Player panel (MVP)

@@ -11,6 +17,7 @@ +
Klar.
@@ -18,7 +25,9 @@ function code(){return document.getElementById("code").value.trim().toUpperCase();} function pid(){return document.getElementById("playerId").value.trim();} 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.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.player&&d.player.id){document.getElementById("playerId").value=d.player.id;}if(d.player&&d.player.session_token){document.getElementById("sessionToken").value=d.player.session_token;}if(d.round_question&&d.round_question.id){document.getElementById("roundQuestionId").value=d.round_question.id;}return d;} +function setGuess(text){document.getElementById("guessText").value=text;var buttons=document.querySelectorAll("#answerOptions button");buttons.forEach(function(btn){btn.classList.toggle("active",btn.dataset.answer===text);});} +function renderAnswerOptions(roundQuestion){var wrap=document.getElementById("answerOptions");wrap.innerHTML="";if(!roundQuestion||!Array.isArray(roundQuestion.answers)){return;}roundQuestion.answers.forEach(function(item){if(!item||!item.text){return;}var btn=document.createElement("button");btn.type="button";btn.dataset.answer=item.text;btn.textContent=item.text;btn.onclick=function(){setGuess(item.text);};wrap.appendChild(btn);});} +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.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.player&&d.player.id){document.getElementById("playerId").value=d.player.id;}if(d.player&&d.player.session_token){document.getElementById("sessionToken").value=d.player.session_token;}if(d.round_question&&d.round_question.id){document.getElementById("roundQuestionId").value=d.round_question.id;}if(d.round_question){renderAnswerOptions(d.round_question);}return d;} function joinSession(){return api("/lobby/sessions/join","POST",{code:code(),nickname:document.getElementById("nickname").value.trim()});} function sessionDetail(){return api("/lobby/sessions/"+code(),"GET",null);} function submitLie(){return api("/lobby/sessions/"+code()+"/questions/"+rq()+"/lies/submit","POST",{player_id:parseInt(pid(),10),session_token:document.getElementById("sessionToken").value,text:document.getElementById("lieText").value});} diff --git a/lobby/tests.py b/lobby/tests.py index 157e3a1..1954f4d 100644 --- a/lobby/tests.py +++ b/lobby/tests.py @@ -780,6 +780,8 @@ class UiScreenTests(TestCase): self.assertContains(response, "Player panel") self.assertContains(response, "id=\"sessionToken\"") self.assertContains(response, "session_token") + self.assertContains(response, "id=\"answerOptions\"") + self.assertContains(response, "renderAnswerOptions") class SessionDetailRoundQuestionTests(TestCase):