diff options
| author | Maks Jopek <maksymilian.jopek@prym-soft.pl> | 2021-04-10 01:06:09 +0200 |
|---|---|---|
| committer | Maks Jopek <maksymilian.jopek@prym-soft.pl> | 2021-04-10 01:06:09 +0200 |
| commit | dd66b8ad239d5ceae219746a702963645259b784 (patch) | |
| tree | 47462463911a018a31cd1ede3d8206fd96032b99 /frontend/ts/login.ts | |
| parent | d928eab3ecefbf778f1cadece9beac010dc42332 (diff) | |
| download | fia-dd66b8ad239d5ceae219746a702963645259b784.tar.gz fia-dd66b8ad239d5ceae219746a702963645259b784.tar.zst fia-dd66b8ad239d5ceae219746a702963645259b784.zip | |
Added joining rooms and logic to start game by votes
Diffstat (limited to 'frontend/ts/login.ts')
| -rw-r--r-- | frontend/ts/login.ts | 39 |
1 files changed, 24 insertions, 15 deletions
diff --git a/frontend/ts/login.ts b/frontend/ts/login.ts index 4ef46ab..5b09e89 100644 --- a/frontend/ts/login.ts +++ b/frontend/ts/login.ts @@ -1,26 +1,35 @@ +import { json } from "express"; import startGame from "./startGame.js"; +// import { Data, Color } from "../../helpers/helpers.js"; let html = /* html */ ` <div class="container text-center fs-1" style="margin-top: 45vh;"> <label for="username">Vad heter du?</label> - <input type="text" name="username" required> + <input type="text" name="username" required> <button type="button" class="btn btn-light btn-lg" onclick="login">Starta spelet</button> </div> `; -async function login() { - let username = document.getElementsByTagName("input")[0].innerHTML, - res = await fetch("/login", { - method: "POST", - headers: { - Accept: "application/json", - "Content-Type": "application/json" - }, - body: JSON.stringify({ username: username }) - }); - res = await res.json(); - startGame(res); +async function login(username = "") { + if (username === "") + username = document.getElementsByTagName("input")[0].value; + let res = await fetch("/login", { + method: "POST", + headers: { + Accept: "application/json", + "Content-Type": "application/json" + }, + body: JSON.stringify({ name: username }) + }); + startGame(await res.json()); } -document.body.innerHTML = html; -document.getElementsByTagName("button")[0].onclick = login; +(async () => { + let res = await (await fetch("/startPoint")).json(); + if (res.status === true) { + startGame(JSON.parse(res.data[0].data)); + } else { + document.body.innerHTML = html; + document.getElementsByTagName("button")[0].onclick = () => login(); + } +})()
\ No newline at end of file |
