From c479b34bc340aaec7df8926321b47cdb5497f2dc Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Sat, 26 Jun 2021 00:34:40 +0200 Subject: Handle deleted games in new join page. --- public/join.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'public/join.js') diff --git a/public/join.js b/public/join.js index 96ca321..31d2bcc 100644 --- a/public/join.js +++ b/public/join.js @@ -1,11 +1,12 @@ "use strict"; let evtsrc = null; +let timer = 0; function confirm_delete(status) { let warning = "Are you sure you want to DELETE this game?"; if (window.confirm(warning)) - window.open("/delete/" + game.game_id); + window.location.href = "/delete/" + game.game_id; } function send(url) { @@ -34,10 +35,16 @@ function start_event_source() { evtsrc.addEventListener("game", function (evt) { console.log("GAME:", evt.data); game = JSON.parse(evt.data); - if (game.status > 1) + if (game.status > 1) { + clearInterval(timer); evtsrc.close(); + } update(); }); + evtsrc.addEventListener("deleted", function (evt) { + console.log("DELETED"); + window.location.href = '/info/' + game.title_id; + }); evtsrc.onerror = function (err) { window.message.innerHTML = "Disconnected from server..."; }; @@ -104,6 +111,6 @@ window.onload = function () { update(); if (game.status < 2) { start_event_source(); - setInterval(start_event_source, 15000); + timer = setInterval(start_event_source, 15000); } } -- cgit v1.2.3