Skip to content

Commit

Permalink
Merged in r2-2598-pn-action (pull request #6536)
Browse files Browse the repository at this point in the history
R2-2598: Going to application when push notification clicked
  • Loading branch information
jtoliver-quoin authored and pnabutovsky committed Oct 11, 2023
2 parents c08cc00 + fc946e6 commit e1f031f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 29 deletions.
45 changes: 17 additions & 28 deletions app/javascript/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ const METHODS = {
DELETE: "DELETE"
};

const ACTIONS = {
GOTO: "goto"
};

const isNav = event => event.request.mode === "navigate";

// TODO: This pr would allow passing strategies to workbox way of handling navigation routes
Expand Down Expand Up @@ -104,38 +100,31 @@ self.addEventListener("push", event => {
body: message.body,
image,
icon: image,
data: { url: message.link },
actions: [{ action: ACTIONS.GOTO, title: message.action_label }]
data: { url: message.link }
})
);
});

self.addEventListener(
"notificationclick",
async event => {
event => {
event.notification.close();

if (event.action === ACTIONS.GOTO) {
event.waitUntil(
self.clients
.matchAll({
type: "window"
})
.then(clientList => {
const link = `${self.location.protocol}//${event.notification.data.url}`;

for (let clientCounter = 0; clientCounter < clientList.length; clientCounter += 1) {
const client = clientList[clientCounter];

if (client.url === link && "focus" in client) {
return client.focus();
}
}

return self.clients.openWindow(link);
})
);
}
event.waitUntil(
self.clients.matchAll().then(clientList => {
const link = `${self.location.protocol}//${event.notification.data.url}`;

for (let clientCounter = 0; clientCounter < clientList.length; clientCounter += 1) {
const client = clientList[clientCounter];

if (client.url === link && "focus" in client) {
return client.focus();
}
}

return self.clients.openWindow(link);
})
);
},
false
);
2 changes: 1 addition & 1 deletion public/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Primero is an open source software platform that helps social services, humanitarian and development workers manage protection-related data, with tools that facilitate case management, incident monitoring and family tracing and reunification.",
"start_url": "v2/",
"background_color": "#ffffff",
"display": "fullscreen",
"display": "standalone",
"theme_color": "#0093ba",
"icons": [
{
Expand Down

0 comments on commit e1f031f

Please sign in to comment.