diff options
Diffstat (limited to 'frontend/sw.js')
| -rw-r--r-- | frontend/sw.js | 40 |
1 files changed, 37 insertions, 3 deletions
diff --git a/frontend/sw.js b/frontend/sw.js index f0ba7d8..bd38341 100644 --- a/frontend/sw.js +++ b/frontend/sw.js @@ -2,7 +2,41 @@ self.addEventListener('push', (e) => { console.log(e.data); const data = e.data.json(); console.log(data); - self.registration.showNotification(data.title, { - body: data.body, - }); + if (data.requireInteraction) { + self.registration.showNotification(data.title, { + body: data.body, + vibrate: [200, 100, 200], + requireInteraction: data.requireInteraction, + actions: [ + { + title: "I've collected my laundry!", + action: "collect", + } + ], + data: {timerId: data.timerId}, + }); + } else { + self.registration.showNotification(data.title, { + body: data.body, + vibrate: [200, 100, 200], + }); + } +}); + +self.addEventListener("notificationclick", (event) => { + if (event.action === "collect") { + timerId = event.data.timerId; + console.log("finishing timer! w/ id "+timerId.toString()); + fetch(`${API_URL}/finish`, { + method: "POST", + credentials: "include", + headers: { + "Content-Type": "application/json" + }, + body: JSON.stringify({id: timerId}), + }); + clients.openWindow("/timer/"); + } else { + clients.openWindow("/timer/"); + } }); |
