Docker-ready Next.js + Prisma/Postgres e-invitation app: themed invite pages, RSVP, comments, share links, email + SMS invites with reply-to-RSVP-by-text, co-hosts, photo dropbox, and browser push notifications.
29 lines
851 B
JavaScript
29 lines
851 B
JavaScript
self.addEventListener('push', (event) => {
|
|
let payload = { title: 'E-Invite', body: '' };
|
|
try {
|
|
if (event.data) payload = event.data.json();
|
|
} catch {
|
|
// Ignore malformed payloads rather than crashing the service worker.
|
|
}
|
|
|
|
event.waitUntil(
|
|
self.registration.showNotification(payload.title || 'E-Invite', {
|
|
body: payload.body || '',
|
|
data: { url: payload.url || '/' },
|
|
})
|
|
);
|
|
});
|
|
|
|
self.addEventListener('notificationclick', (event) => {
|
|
event.notification.close();
|
|
const url = event.notification.data?.url || '/';
|
|
event.waitUntil(
|
|
self.clients.matchAll({ type: 'window' }).then((clients) => {
|
|
for (const client of clients) {
|
|
if (client.url === url && 'focus' in client) return client.focus();
|
|
}
|
|
if (self.clients.openWindow) return self.clients.openWindow(url);
|
|
})
|
|
);
|
|
});
|