Release 202506091000
This commit is contained in:
29
web/src/components/NotificationEventsScript.astro
Normal file
29
web/src/components/NotificationEventsScript.astro
Normal file
@@ -0,0 +1,29 @@
|
||||
---
|
||||
|
||||
---
|
||||
|
||||
<script>
|
||||
import { isBrowserNotificationsEnabled, showBrowserNotification } from '../lib/client/browserNotifications'
|
||||
import { makeNotificationOptions } from '../lib/notificationOptions'
|
||||
|
||||
document.addEventListener('sse-new-notification', (event) => {
|
||||
if (isBrowserNotificationsEnabled()) {
|
||||
const payload = event.detail
|
||||
const notification = showBrowserNotification(
|
||||
payload.title,
|
||||
makeNotificationOptions(payload, { removeActions: true })
|
||||
)
|
||||
|
||||
// Handle notification click
|
||||
if (notification) {
|
||||
notification.onclick = () => {
|
||||
const defaultAction = payload.actions.find((a) => a.url) ?? payload.actions[0]
|
||||
if (defaultAction?.url) {
|
||||
window.open(defaultAction.url, '_blank')
|
||||
}
|
||||
notification.close()
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
</script>
|
||||
Reference in New Issue
Block a user