Skip to content

Commit

Permalink
Add dispatch block to the notification handler
Browse files Browse the repository at this point in the history
  • Loading branch information
ikprk committed Jul 22, 2024
1 parent 92a6d65 commit 21f59a6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
9 changes: 8 additions & 1 deletion packages/atlas/src/api/hooks/notifications.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { QueryHookOptions } from '@apollo/client'
import { useRef } from 'react'

import {
GetNftActivitiesCountQuery,
Expand All @@ -10,15 +11,21 @@ import {
useGetNotificationsConnectionQuery,
useMarkNotificationsAsReadMutation,
} from '@/api/queries/__generated__/notifications.generated'
import { useJoystreamStore } from '@/providers/joystream/joystream.store'

import { NftActivityOrderByInput, RecipientTypeWhereInput } from '../queries/__generated__/baseTypes.generated'

export const useRawNotifications = (
recipient: RecipientTypeWhereInput | undefined,
opts?: Pick<QueryHookOptions, 'notifyOnNetworkStatusChange'>
) => {
const currentBlockRef = useRef(useJoystreamStore((store) => store.currentBlock))
const { data, ...rest } = useGetNotificationsConnectionQuery({
variables: { first: 10, recipient: recipient as RecipientTypeWhereInput },
variables: {
first: 10,
recipient: recipient as RecipientTypeWhereInput,
dispatchBlock: currentBlockRef.current ?? 0,
},
...opts,
skip: !recipient,
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
import { FC, useEffect } from 'react'
import { FC, useEffect, useRef } from 'react'

import { atlasConfig } from '@/config'

import { useNotifications } from './notifications.hooks'

import { useJoystreamStore } from '../joystream/joystream.store'

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

useEffect(() => {
if (currentBlock) {
currentBlockRef.current = currentBlock
}
}, [currentBlock])

useEffect(() => {
const id = setInterval(() => {
Expand All @@ -15,6 +25,9 @@ export const NotificationsManager: FC = () => {

unseenNotificationsCounts.fetchMore()
fetchMore({
variables: {
dispatchBlock: currentBlockRef.current,
},
updateQuery: (prev, { fetchMoreResult }) => {
if (!Object.keys(prev).length) {
return fetchMoreResult
Expand Down

0 comments on commit 21f59a6

Please sign in to comment.