diff options
Diffstat (limited to 'frontend/start.js')
| -rw-r--r-- | frontend/start.js | 66 |
1 files changed, 40 insertions, 26 deletions
diff --git a/frontend/start.js b/frontend/start.js index c36dc40..82e23aa 100644 --- a/frontend/start.js +++ b/frontend/start.js @@ -1,35 +1,11 @@ -const notif = document.getElementById("notif-panel"); -const notbtn = document.getElementById("notbtn"); const startbtn = document.getElementById("startbtn"); -startbtn.addEventListener("click", () => { - start(); -}); - const urlParams = new URLSearchParams(window.location.search); data.machine_id = urlParams.get('machine'); console.log(urlParams); startUpdateMachines(); -OneSignalDeferred.push(async function(OneSignal) { - if (OneSignal.Notifications.permission) { - notif.remove(); - startbtn.disabled = false; - } - data.onesignal_subscription_id = OneSignal.User.PushSubscription["id"] ; -}); - -notbtn.addEventListener("click", () => requestPermission()) -async function requestPermission() { - console.log("Requesting permission..."); - const onesignal_result = await OneSignal.Notifications.requestPermission(); - if (onesignal_result) { - notif.remove(); - startbtn.disabled = false; - } -} - (async () => { const timers = await fetchTimers(); @@ -38,12 +14,50 @@ async function requestPermission() { const existingPanel = document.getElementById("existing-laundry-panel"); const existingText = document.getElementById("existing-laundry-text"); - if (timers[1].length > 0) { + if (Array.isArray(timers[1]) && timers[1].length > 0) { existingPanel.style.display = 'inherit'; - if (timers.length == 1) { + if (timers[1].length == 1) { existingText.innerText = "You currently have another ongoing laundry. You are creating a new timer."; } else { existingText.innerText = "You currently have other ongoing laundries. You are creating a new timer."; } } + + const info = await information(data.machine_id); + + const machine = await info["machine"]; + + console.log(`machine is ${machine}`); + + const divs = [ + document.getElementById("dryer1"), + document.getElementById("washer1"), + document.getElementById("dryer2"), + document.getElementById("washer2"), + ] + + divs[machine - 1].classList.add("machine-selected"); + + cookie = await cookieStore.get("subscription_endpoint"); + + if (cookie) { + startbtn.disabled = false; + } })(); + +startbtn.addEventListener("click", () => { + start(); +}); + +function rememberUrl() { + machineId = urlParams.get('machine'); + minutesDelta = 5; + expirationDate = new Date(new Date().getTime() + minutesDelta * 60000);; + cookieStore.set({ + expires: expirationDate, + name: "last_used_url", + value: machineId, + url: "https://laundryweb.altafcreator.com", + secure: true, + }) +} |
