Request pages until we receive more items
This commit is contained in:
@@ -59,7 +59,6 @@ export function useNotificationFeedQuery(opts?: {
|
||||
const moderationOpts = useModerationOpts()
|
||||
const unreads = useUnreadNotificationsApi()
|
||||
const enabled = opts?.enabled !== false
|
||||
const lastPageCountRef = useRef(0)
|
||||
const gate = useGate()
|
||||
|
||||
// false: force showing all notifications
|
||||
@@ -121,29 +120,21 @@ export function useNotificationFeedQuery(opts?: {
|
||||
},
|
||||
})
|
||||
|
||||
const lastItemsCountRef = useRef(0)
|
||||
useEffect(() => {
|
||||
const {isFetching, hasNextPage, data} = query
|
||||
if (isFetching || !hasNextPage) {
|
||||
return
|
||||
}
|
||||
|
||||
// avoid double-fires of fetchNextPage()
|
||||
if (
|
||||
lastPageCountRef.current !== 0 &&
|
||||
lastPageCountRef.current === data?.pages?.length
|
||||
) {
|
||||
return
|
||||
}
|
||||
|
||||
// fetch next page if we haven't gotten a full page of content
|
||||
let count = 0
|
||||
for (const page of data?.pages || []) {
|
||||
count += page.items.length
|
||||
}
|
||||
if (count < PAGE_SIZE && (data?.pages.length || 0) < 6) {
|
||||
query.fetchNextPage()
|
||||
lastPageCountRef.current = data?.pages?.length || 0
|
||||
if (count > lastItemsCountRef.current) {
|
||||
lastItemsCountRef.current = count
|
||||
return
|
||||
}
|
||||
query.fetchNextPage()
|
||||
}, [query])
|
||||
|
||||
return query
|
||||
|
||||
Reference in New Issue
Block a user