stacker.news/pages/notifications.js
ekzyis b1a0abe32c
Service Worker rewrite (#2274)
* Convert all top-level arrow functions to regular functions

* Refactor webPush.sendNotification call

* Refactor webPush logging

* Rename var to title

* Rewrite service worker

This rewrite simplifies the service worker by removing

* merging of push notifications via tag property
* badge count

These features weren't properly working on iOS. We concluded that we don't really need them.

For example, this means replies will no longer get merged to "you have X new replies" but show up as individual notifications.

Only zaps still use the tag property so devices that support it can still replace any previous "your post stacked X sats" notification for the same item.

* Don't use async/await in service worker

* Support app badge count

* Fix extremely slow notificationclick

* Fix serialization and save in pushsubscriptionchange event
2025-07-10 11:54:23 -05:00

31 lines
885 B
JavaScript

import { useEffect } from 'react'
import { getGetServerSideProps } from '@/api/ssrApollo'
import Layout from '@/components/layout'
import Notifications, { NotificationAlert } from '@/components/notifications'
import { HAS_NOTIFICATIONS, NOTIFICATIONS } from '@/fragments/notifications'
import { useApolloClient } from '@apollo/client'
import { clearNotifications } from '@/components/serviceworker'
export const getServerSideProps = getGetServerSideProps({ query: NOTIFICATIONS, authRequired: true })
export default function NotificationPage ({ ssrData }) {
const client = useApolloClient()
useEffect(() => {
client?.writeQuery({
query: HAS_NOTIFICATIONS,
data: {
hasNewNotes: false
}
})
clearNotifications()
}, [ssrData])
return (
<Layout>
<NotificationAlert />
<Notifications ssrData={ssrData} />
</Layout>
)
}