Skip to content

Commit

Permalink
🛑 Stop polling if notifications recipient is undefined (Joystream#5695)
Browse files Browse the repository at this point in the history
  • Loading branch information
WRadoslaw committed Dec 29, 2023
1 parent e3e000d commit 2227dcc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export type UseNotifications = Pick<QueryResult<GetNotificationsConnectionQuery>
setLastSeenNotificationDate: (data: Date) => void
markNotificationsAsRead: (notifications: NotificationRecord[]) => void
pageInfo?: GetNotificationsConnectionQuery['notificationsConnection']['pageInfo']
recipient: RecipientTypeWhereInput | undefined
}

export const useNotifications = (opts?: Pick<QueryHookOptions, 'notifyOnNetworkStatusChange'>): UseNotifications => {
Expand Down Expand Up @@ -120,6 +121,7 @@ export const useNotifications = (opts?: Pick<QueryHookOptions, 'notifyOnNetworkS
unseenNotificationsCounts,
setLastSeenNotificationDate,
markNotificationsAsRead,
recipient,
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@ import { atlasConfig } from '@/config'
import { useNotifications } from './notifications.hooks'

export const NotificationsManager: FC = () => {
const { fetchMore, unseenNotificationsCounts } = useNotifications()
const { fetchMore, unseenNotificationsCounts, recipient } = useNotifications()

useEffect(() => {
const id = setInterval(() => {
if (!recipient) {
return
}

unseenNotificationsCounts.fetchMore()
fetchMore({
updateQuery: (prev, { fetchMoreResult }) => {
Expand Down Expand Up @@ -44,7 +48,7 @@ export const NotificationsManager: FC = () => {
clearInterval(id)
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [fetchMore, unseenNotificationsCounts.fetchMore])
}, [fetchMore, unseenNotificationsCounts.fetchMore, !recipient])

return null
}

0 comments on commit 2227dcc

Please sign in to comment.