stacker.news/pages/notifications.js
SatsAllDay 522c821c89
Notification badges (#595)
* First pass of implementing Badging API for notifications

* Only show app badge when driven from push notifications

* Display number of unread push notifications instead of just an empty badge

Clear badge via postMessage when notifications page is loaded

* de-dupe some code, update badge counter on each notification click

* remove ids, track open note count instead

* restore optional chaining

* ensure note count doesn't go below 0, and fix event.waitUntil error when clearing badge

* incorporate PR feedback
2023-11-08 18:17:01 -06:00

31 lines
875 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 '../lib/badge'
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>
)
}