-
Notifications
You must be signed in to change notification settings - Fork 7
/
sw.js
109 lines (89 loc) · 2.69 KB
/
sw.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/* eslint-disable no-restricted-globals */
/* eslint-disable no-undef */
if('function' === typeof importScripts){
importScripts('https://storage.googleapis.com/workbox-cdn/releases/5.1.2/workbox-sw.js')
}
if (workbox) {
console.log(`Yay! Workbox is loaded 🎉`);
} else {
console.log(`Boo! Workbox didn't load 😬`);
}
const x = self;
self.addEventListener('install',()=>{
console.log('I am installed')
})
const addSymptom = new workbox.backgroundSync.BackgroundSyncPlugin('symptomQueue', {
maxRetentionTime: 24 * 60,
onSync({ queue }) {
// !!! important call here !!!
queue.replayRequests();
x.registration.showNotification('Your symptoms have been updated')
}
});
const addRemark = new workbox.backgroundSync.BackgroundSyncPlugin('addRemarkQueue', {
maxRetentionTime: 24 * 60,
onSync({ queue }) {
// !!! important call here !!!
queue.replayRequests();
x.registration.showNotification('Your remark has been added to the patient')
}
});
const editRemark = new workbox.backgroundSync.BackgroundSyncPlugin('editRemarkQueue', {
maxRetentionTime: 24 * 60,
onSync({ queue }) {
// !!! important call here !!!
queue.replayRequests();
x.registration.showNotification('Your remark has been edited successfully')
}
});
const deleteRemark = new workbox.backgroundSync.BackgroundSyncPlugin('deleteRemarkQueue', {
maxRetentionTime: 24 * 60,
onSync({ queue }) {
// !!! important call here !!!
queue.replayRequests();
x.registration.showNotification('Your remark has been deleted successfully')
}
});
const flag = new workbox.backgroundSync.BackgroundSyncPlugin('flagQueue', {
maxRetentionTime: 24 * 60,
onSync({ queue }) {
// !!! important call here !!!
queue.replayRequests();
x.registration.showNotification('The Patient has been flagged successfully')
}
});
workbox.routing.registerRoute(
'https://fast-hamlet-28566.herokuapp.com/api/add_symptoms',
new workbox.strategies.NetworkFirst({
plugins: [addSymptom]
}),
'POST'
)
workbox.routing.registerRoute(
'https://fast-hamlet-28566.herokuapp.com/doctors/add_remark',
new workbox.strategies.NetworkFirst({
plugins: [addRemark]
}),
'POST'
)
workbox.routing.registerRoute(
'https://fast-hamlet-28566.herokuapp.com/doctors/edit_remark/1',
new workbox.strategies.NetworkFirst({
plugins: [editRemark]
}),
'PUT'
)
workbox.routing.registerRoute(
'https://fast-hamlet-28566.herokuapp.com/doctors/delete_remark/1',
new workbox.strategies.NetworkFirst({
plugins: [deleteRemark]
}),
'DELETE'
)
workbox.routing.registerRoute(
'https://fast-hamlet-28566.herokuapp.com/doctors/flag',
new workbox.strategies.NetworkFirst({
plugins: [flag]
}),
'POST'
)