From b35d6ac5246d79d94f3f6bd9171f6c122145bff5 Mon Sep 17 00:00:00 2001 From: IM23a-spirgif Date: Thu, 17 Apr 2025 15:42:24 +0200 Subject: [PATCH] Formatting + Added Home Page --- public/frontend_home.js | 28 ++++++++++++++++++++++++++++ public/home.html | 12 +++++++++--- public/styles_home.css | 26 ++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 3 deletions(-) diff --git a/public/frontend_home.js b/public/frontend_home.js index e8477c4..dd2f7a5 100644 --- a/public/frontend_home.js +++ b/public/frontend_home.js @@ -1,6 +1,8 @@ document.addEventListener("DOMContentLoaded", async () => { const logoutButton = document.getElementById("logout"); const balance = document.getElementById("balance"); + const hostButton = document.getElementById("host"); + const joinButton = document.getElementById("join"); try { const balanceRes = await fetch('/balance', { method: "GET", @@ -36,4 +38,30 @@ document.addEventListener("DOMContentLoaded", async () => { console.log("Logout error:", err); } }); + hostButton.addEventListener("click", async (e) => { + e.preventDefault(); + try { + const hostRes = await fetch('/lobby/create', { + method: "GET", + headers: { + "Content-Type": "application/json", + } + }); + if (hostRes.ok) { + const lobbyId = await hostRes.text(); + document.getElementById("lobby-id").textContent = lobbyId; + document.getElementById("lobby-room").classList.remove("hidden"); + setInterval(async () => { + const res = await fetch(`/lobby/players?lobbyId=${lobbyId}`); + const data = await res.json(); + const playerList = document.getElementById("player-list"); + playerList.innerHTML = data.players.map(p => `

${p}

`).join("") || "

No players yet

"; + }, 3000); + } else { + console.log("Failed to create lobby:" + await hostRes.text()); + } + } catch (err) { + console.log("Lobby create error:", err); + } + }); }); \ No newline at end of file diff --git a/public/home.html b/public/home.html index b45a745..dadeb1d 100644 --- a/public/home.html +++ b/public/home.html @@ -4,7 +4,6 @@ Home - @@ -12,8 +11,15 @@ Balance: $0
- - + + +
+ + \ No newline at end of file diff --git a/public/styles_home.css b/public/styles_home.css index 4b82836..fd7d0e3 100644 --- a/public/styles_home.css +++ b/public/styles_home.css @@ -56,4 +56,30 @@ button.logout { display: flex; gap: 20px; margin-top: 30px; +} + +.lobby-room { + background: rgba(0, 0, 0, 0.7); + border: 2px solid #0f0; + border-radius: 12px; + padding: 30px; + margin-top: 40px; + width: 400px; + text-align: center; + box-shadow: 0 0 10px #0f0; +} + +.lobby-room h2 { + color: #0f0; + font-size: 20px; + margin-bottom: 20px; + text-shadow: 0 0 5px #0f0; +} + +#player-list { + color: #fff; +} + +.hidden { + display: none; } \ No newline at end of file