Implement error message
This commit is contained in:
parent
2bc842665d
commit
b3aff0bf81
@ -7,7 +7,11 @@ const api_path = `../../api/token${token}/`;
|
|||||||
const greeting = document.getElementById("greeting"),
|
const greeting = document.getElementById("greeting"),
|
||||||
currentcoins = document.getElementById("currentcoins"),
|
currentcoins = document.getElementById("currentcoins"),
|
||||||
maxcoins = document.getElementById("maxcoins"),
|
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() {
|
async function redraw() {
|
||||||
|
|
||||||
@ -27,7 +31,7 @@ async function redraw() {
|
|||||||
currentcoins.innerText = user.score;
|
currentcoins.innerText = user.score;
|
||||||
maxcoins.innerText = user.maxscore;
|
maxcoins.innerText = user.maxscore;
|
||||||
sellvalue.max = user.maxscore - user.score;
|
sellvalue.max = user.maxscore - user.score;
|
||||||
|
sellvalue.value = Math.min(sellvalue.value, sellvalue.max);
|
||||||
}
|
}
|
||||||
|
|
||||||
redraw();
|
redraw();
|
||||||
@ -36,7 +40,6 @@ const button = document.getElementById("sell");
|
|||||||
|
|
||||||
button.addEventListener("click", async () => {
|
button.addEventListener("click", async () => {
|
||||||
const newscore = parseInt(currentcoins.innerText) + parseInt(sellvalue.value);
|
const newscore = parseInt(currentcoins.innerText) + parseInt(sellvalue.value);
|
||||||
console.log(newscore);
|
|
||||||
|
|
||||||
const r = await fetch(api_path + 'set_score', {
|
const r = await fetch(api_path + 'set_score', {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
@ -46,9 +49,25 @@ button.addEventListener("click", async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (r.status !== 200) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
redraw();
|
redraw();
|
||||||
})
|
})
|
||||||
|
|
||||||
|
errorclose.addEventListener("click", () => {
|
||||||
|
errormesssage.style.display = "none";
|
||||||
|
})
|
71
user.html
71
user.html
@ -3,30 +3,52 @@
|
|||||||
<html lang="en">
|
<html lang="en">
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
|
|
||||||
<title>Waschmarken.io</title>
|
<title>Waschmarken.io</title>
|
||||||
<meta name="description" content="Waschmarken Scoreboard">
|
<meta name="description" content="Waschmarken Scoreboard">
|
||||||
|
|
||||||
<link rel="stylesheet" href="../../static/css/normalize.css">
|
<link rel="stylesheet" href="../../static/css/normalize.css">
|
||||||
<link rel="stylesheet" href="../../static/css/sakura-dark.css">
|
<link rel="stylesheet" href="../../static/css/sakura-dark.css">
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
.heading {
|
.heading {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
#thetable {
|
#thetable {
|
||||||
margin-bottom : 2rem;
|
margin-bottom: 2rem;
|
||||||
}
|
}
|
||||||
.biceps {
|
|
||||||
display: flex;
|
.flex {
|
||||||
justify-content: space-around;
|
display: flex;
|
||||||
}
|
}
|
||||||
input {
|
|
||||||
width: 8rem;
|
.biceps {
|
||||||
}
|
justify-content: space-around;
|
||||||
</style>
|
}
|
||||||
|
|
||||||
|
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>
|
</head>
|
||||||
|
|
||||||
@ -49,13 +71,18 @@
|
|||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
<div class="biceps">
|
<div class="flex biceps">
|
||||||
<div>
|
<div>
|
||||||
<input type="number" id="sellvalue" value = "1" >
|
<input type="number" id="sellvalue" value="1" min="0">
|
||||||
<button id="sell">Sell</button>
|
<button id="sell">Sell</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div id="errormessage">
|
||||||
|
<span id="errortext"></span>
|
||||||
|
<span id="errorclose">×</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
<script src="../../static/js/user.js"></script>
|
<script src="../../static/js/user.js"></script>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user