From dd0490ee139764954091a962c6b2d34120816aac Mon Sep 17 00:00:00 2001 From: Kai Vogelgesang Date: Fri, 17 Apr 2020 02:33:24 +0200 Subject: [PATCH] Change all_sessions to buttons --- static/renderer.js | 13 ++++++++++++- ui.html | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/static/renderer.js b/static/renderer.js index b67fe53..9595eb7 100644 --- a/static/renderer.js +++ b/static/renderer.js @@ -12,6 +12,17 @@ ws.onmessage = function(event) { } if (msg.hasOwnProperty('allsessions')) { - document.getElementById('all_sessions').innerText = msg.allsessions.join(', '); + const all_sessions = document.getElementById('all_sessions'); + + while (all_sessions.children.length) all_sessions.lastChild.remove(); + + for (let session of msg.allsessions) { + const button = document.createElement('button'); + button.innerText = session; + button.onclick = async (e) => await fetch('api/join_session', { + method: 'POST', body: JSON.stringify({sessionid: session}) + }); + all_sessions.appendChild(button); + } } }; \ No newline at end of file diff --git a/ui.html b/ui.html index b623d8a..4da1b9e 100644 --- a/ui.html +++ b/ui.html @@ -10,7 +10,7 @@ this is the UI
You are not in any session.
-
+