diff --git a/Public/api.js b/Public/api.js index 50f3505..a477897 100644 --- a/Public/api.js +++ b/Public/api.js @@ -54,6 +54,12 @@ async function performGetPublicTablesRequest(token) { }) } +async function performLeaveTableRequest(token) { + return fetch("/table/leave", { method: 'POST', body: token }) + .then(convertServerResponse) + .then(function(value) {}) +} + function convertServerResponse(response) { switch (response.status) { case 200: // Success diff --git a/Public/elements.js b/Public/elements.js index 62a1259..508cfb8 100644 --- a/Public/elements.js +++ b/Public/elements.js @@ -20,6 +20,14 @@ function showTableListElements() { document.getElementById("table-list").style.display = "inherit" } +function showGameElements() { + document.getElementById("game-bar").style.display = "grid" +} + +function hideGameElements() { + document.getElementById("game-bar").style.display = "none" +} + function setPlayerName(name) { document.getElementById("player-name").innerHTML = name } diff --git a/Public/game.js b/Public/game.js index 1f1d76a..7a82c3c 100644 --- a/Public/game.js +++ b/Public/game.js @@ -39,6 +39,7 @@ function showGame(tableId) { if (token) { openSocket(token) hideTableListElements() + showGameElements() // TODO: Show interface console.log("Show table " + tableId) } else { @@ -186,6 +187,22 @@ function joinTable(tableId) { } } +function leaveTable() { + const token = getSessionToken() + if (token) { + performLeaveTableRequest(token) + .then(function() { + showTableList() + hideGameElements() + }) + .catch(function(error) { + showBlankLoginScreen(error.message) + }) + } else { + showBlankLoginScreen("") + } +} + function openSocket(token) { socket = new WebSocket(((window.location.protocol === "https:") ? "wss://" : "ws://") + window.location.host + "/session/start") diff --git a/Public/schafkopf.html b/Public/schafkopf.html index d911dde..579ff42 100644 --- a/Public/schafkopf.html +++ b/Public/schafkopf.html @@ -22,6 +22,9 @@ +
+ +
diff --git a/Public/style.css b/Public/style.css index a61fd08..364a15b 100644 --- a/Public/style.css +++ b/Public/style.css @@ -157,6 +157,28 @@ body, html { height: 34px; } + +#game-bar { + position: absolute; + width: 120px; + height: 40px; + top: 5px; + left: 10px; + display: none; + grid-template-columns: 1200px; + column-gap: 10px; + align-items: center; + justify-content: center; + justify-items: center; +} + +#leave-table { + width: 120px; + grid-column: 1; + padding: 0px; + height: 34px; +} + #table-list { margin: 20px; padding-right: 20px;