feat(RECIPE-0009): complete iteration 0 — deduplication, notifications, UI improvements
This commit is contained in:
@@ -183,22 +183,36 @@ self.addEventListener('notificationclick', (event) => {
|
||||
|
||||
let url = '/';
|
||||
|
||||
if (action === 'view' && data?.itemId) {
|
||||
url = `/?highlight=${data.itemId}`;
|
||||
// Handle 'view' action - redirect to Tandoor if available
|
||||
if (action === 'view') {
|
||||
if (data?.tandoorUrl) {
|
||||
// Success notification with Tandoor URL - redirect to recipe
|
||||
url = data.tandoorUrl;
|
||||
} else if (data?.itemId) {
|
||||
// Fallback to dashboard highlight
|
||||
url = `/?highlight=${data.itemId}`;
|
||||
}
|
||||
} else if (action === 'retry' && data?.itemId) {
|
||||
// Navigate to dashboard and trigger retry via postMessage
|
||||
// Navigate to dashboard and trigger retry
|
||||
url = `/?highlight=${data.itemId}&action=retry`;
|
||||
} else if (data?.itemId) {
|
||||
// Default: highlight item in dashboard
|
||||
url = `/?highlight=${data.itemId}`;
|
||||
}
|
||||
|
||||
event.waitUntil(
|
||||
clients.matchAll({ type: 'window', includeUncontrolled: true }).then((clientsList) => {
|
||||
// Check if there's already a window/tab open
|
||||
// For external URLs (Tandoor), always open new window
|
||||
if (url.startsWith('http') && !url.includes(self.location.origin)) {
|
||||
if (clients.openWindow) {
|
||||
return clients.openWindow(url);
|
||||
}
|
||||
}
|
||||
|
||||
// For internal URLs, check for existing window
|
||||
for (const client of clientsList) {
|
||||
if (client.url.includes(self.location.origin) && 'focus' in client) {
|
||||
return client.focus().then(() => {
|
||||
// Send message to the client about the action
|
||||
return client.postMessage({
|
||||
type: 'notification-action',
|
||||
action: action,
|
||||
@@ -208,7 +222,7 @@ self.addEventListener('notificationclick', (event) => {
|
||||
}
|
||||
}
|
||||
|
||||
// If no window is open, open a new one
|
||||
// No window open, open new one
|
||||
if (clients.openWindow) {
|
||||
return clients.openWindow(url);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user