diff options
Diffstat (limited to 'frontend/main.js')
| -rw-r--r-- | frontend/main.js | 43 |
1 files changed, 30 insertions, 13 deletions
diff --git a/frontend/main.js b/frontend/main.js index 3f5c4c4..cfacc86 100644 --- a/frontend/main.js +++ b/frontend/main.js @@ -31,24 +31,28 @@ async function subscribe() { userVisibleOnly: true, applicationServerKey: urlBase64ToUint8Array(PUBLIC_VAPID_KEY), }); + console.log(subscription); + + console.log("sw regis pass, write to db"); + + const db_reply = await fetch(`${API_URL}/notifsubscribe`, { + method: 'POST', + credentials: "include", + body: JSON.stringify(subscription), + headers: { + "Content-Type": "application/json", + }, + }); + + console.log(db_reply) + + return db_reply.ok; } catch (e) { console.log("ERR in regis, ", e); return false; } - console.log("sw regis pass, write to db"); - - const db_reply = await fetch(`${API_URL}/notifsubscribe`, { - method: 'POST', - credentials: "include", - body: JSON.stringify(subscription), - headers: { - "Content-Type": "application/json", - }, - }); - - return db_reply.status == 2000; } /// copied from somewhere @@ -113,6 +117,7 @@ async function start() { if (data == "all good bro timer started") { window.location.href = "/timer/"; } + cookieStore.delete("last_used_url"); }); } @@ -207,7 +212,18 @@ async function updateMachines() { const end = Date.parse(status[2][i]); const minsLeft = Math.ceil((end - now) / 60000).toString(); machineTxts[i].innerHTML = minsLeft + " min(s) left"; - if (machineDetailImgs[0]) machineDetailTitles[i].innerHTML = minsLeft + " minutes left" + if (machineDetailImgs[0]) machineDetailTitles[i].innerHTML = minsLeft + " minute(s) left" + } else if (status[0][i] == "OUTOFSERVICE") { + if ((i + 1) % 2 == 0) { + machineImgs[i].src = "/assets/img/washer_down.png"; + if (machineDetailImgs[0]) machineDetailImgs[i].src = "/assets/img/washer_down.png"; + } else { + machineImgs[i].src = "/assets/img/dryer_down.png"; + if (machineDetailImgs[0]) machineDetailImgs[i].src = "/assets/img/dryer_down.png"; + } + machineTxts[i].innerHTML = "Down" + if (machineDetailImgs[0]) machineDetailTitles[i].innerHTML = "Out of Service" + if (machineDetailImgs[0]) machineDetailDescs[i].innerHTML = "This machine is currently out of service, and is unavailable to use." } else if (status[0][i] == "FINISHED") { if ((i + 1) % 2 == 0) { machineImgs[i].src = "/assets/img/washer_clothes.png"; @@ -250,6 +266,7 @@ async function startLoadTimers() { const timers = timersData[1]; const container = document.getElementById("timer-container") + if (timers.length > 0) container.innerHTML = ''; const textList = [] const progList = [] |
