Merge branch 'master' of leafbla.de:dominic/waschmarken

This commit is contained in:
Dominic Zimmer 2020-07-18 00:55:08 +02:00
commit 9ec1f6239d
3 changed files with 74 additions and 26 deletions

View File

@ -4,6 +4,7 @@
<head>
<meta charset="utf-8">
<meta content="width=device-width, initial-scale=1" name="viewport">
<title>Waschmarken.io</title>
<meta name="description" content="Waschmarken Scoreboard">

View File

@ -7,7 +7,11 @@ const api_path = `../../api/token${token}/`;
const greeting = document.getElementById("greeting"),
currentcoins = document.getElementById("currentcoins"),
maxcoins = document.getElementById("maxcoins"),
sellvalue = document.getElementById("sellvalue");
sellvalue = document.getElementById("sellvalue"),
errormesssage = document.getElementById("errormessage"),
errortext = document.getElementById("errortext"),
errorclose = document.getElementById("errorclose");
async function redraw() {
@ -27,7 +31,7 @@ async function redraw() {
currentcoins.innerText = user.score;
maxcoins.innerText = user.maxscore;
sellvalue.max = user.maxscore - user.score;
sellvalue.value = Math.min(sellvalue.value, sellvalue.max);
}
redraw();
@ -36,7 +40,6 @@ const button = document.getElementById("sell");
button.addEventListener("click", async () => {
const newscore = parseInt(currentcoins.innerText) + parseInt(sellvalue.value);
console.log(newscore);
const r = await fetch(api_path + 'set_score', {
method: "POST",
@ -46,9 +49,25 @@ button.addEventListener("click", async () => {
});
if (r.status !== 200) {
console.log("something went wrong");
if (r.status !== 400) {
console.log("Something went very very wrong!");
return;
}
const data = await r.json();
if (data.error) {
errortext.innerText = data.error;
errormesssage.style.display = "flex";
}
return;
}
redraw();
})
errorclose.addEventListener("click", () => {
errormesssage.style.display = "none";
})

View File

@ -3,30 +3,53 @@
<html lang="en">
<head>
<meta charset="utf-8">
<meta charset="utf-8">
<meta content="width=device-width, initial-scale=1" name="viewport">
<title>Waschmarken.io</title>
<meta name="description" content="Waschmarken Scoreboard">
<title>Waschmarken.io</title>
<meta name="description" content="Waschmarken Scoreboard">
<link rel="stylesheet" href="../../static/css/normalize.css">
<link rel="stylesheet" href="../../static/css/sakura-dark.css">
<link rel="stylesheet" href="../../static/css/normalize.css">
<link rel="stylesheet" href="../../static/css/sakura-dark.css">
<style>
.heading {
text-align: center;
}
<style>
.heading {
text-align: center;
}
#thetable {
margin-bottom : 2rem;
}
.biceps {
display: flex;
justify-content: space-around;
}
input {
width: 8rem;
}
</style>
#thetable {
margin-bottom: 2rem;
}
.flex {
display: flex;
}
.biceps {
justify-content: space-around;
}
input {
width: 8rem;
}
#errormessage {
display: none;
/* flex if visible */
justify-content: space-between;
width: 100%;
border-left: 3px solid red;
padding-left: 1rem;
background: #460000;
color: red;
}
#errorclose {
margin-right: 1rem;
font-weight: bold;
cursor: pointer;
}
</style>
</head>
@ -48,14 +71,19 @@
</tr>
</tbody>
</table>
<div class="biceps">
<div class="flex biceps">
<div>
<input type="number" id="sellvalue" value = "1" >
<input type="button" id="sell" value="Sell">
</div>
</div>
<div id="errormessage">
<span id="errortext"></span>
<span id="errorclose">&times;</span>
</div>
<script src="../../static/js/user.js"></script>
</body>