feat: pixels resfresh every 2s

This commit is contained in:
gdamms 2022-05-20 11:32:19 +02:00
parent 06daf6f6f6
commit 5c31448400
3 changed files with 15 additions and 6 deletions

View file

@ -8,7 +8,6 @@
<link rel="stylesheet" href="title-bar.css">
<link rel="stylesheet" href="login-signup.css">
<link rel="stylesheet" href="pixels.css">
<link rel="stylesheet" href="pix.css">
<script>
function toggleLoginSignup(l, s) {
document.getElementById("show-login").checked = l;

View file

@ -8,7 +8,6 @@
<link rel="stylesheet" href="title-bar.css">
<link rel="stylesheet" href="profil.css">
<link rel="stylesheet" href="pixels.css">
<link rel="stylesheet" href="pix.css">
<link rel="stylesheet" href="wallet.css">
<script>
function setMenu() {

View file

@ -1,9 +1,20 @@
var url = "http://localhost:8080/api/pixel";
function wait(ms) {
var start = new Date().getTime();
var end = start;
while(end < start + ms) {
end = new Date().getTime();
}
}
function setPixels(pixelsJSON) {
var table = document.getElementById("pixelTable");
var num_rows = table.rows.length;
console.log(num_rows)
for (let i = 0; i < num_rows; i++) {
table.rows[i].innerHTML = "";
}
for (i in pixelsJSON) {
var pixel = pixelsJSON[i];
@ -22,11 +33,11 @@ function setPixels(pixelsJSON) {
}
}
const callSetPixels = async () => {
const updatePixels = async () => {
const reponse = await fetch(url);
const pixelsJSON = await reponse.json();
setPixels(pixelsJSON);
}
callSetPixels();
updatePixels();
setInterval(updatePixels, 2000);