Change all_sessions to buttons

This commit is contained in:
Kai Vogelgesang 2020-04-17 02:33:24 +02:00
parent 40dd6ea865
commit dd0490ee13
2 changed files with 13 additions and 2 deletions

View File

@ -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);
}
}
};

View File

@ -10,7 +10,7 @@
this is the UI
<br>
<span id="current_session">You are not in any session.</span><br>
<span id="all_sessions"></span><br>
<div id="all_sessions"></div><br>
<br>
<button id="btn_create_session">Create session</button>
<br><br><br>