diff options
author | Eric Bailey <git@esb.lol> | 2023-12-07 15:44:22 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-07 13:44:22 -0800 |
commit | 174a1622c9dc34d580d3deb1f52f85aec4ac9f42 (patch) | |
tree | d9b6ffe6c8ba20500f55ec7256282e09064fa45f /src/state/queries/notifications/feed.ts | |
parent | 940fc0ea5c3aefb49f39d8de9398a306882ed567 (diff) | |
download | voidsky-174a1622c9dc34d580d3deb1f52f85aec4ac9f42.tar.zst |
Hoist moderation, attempt to fill feed up to 30 (#2134)
* Move moderatePost up to feed query * Attemt to fill page up to 30 * Add the 'ensure full page' behavior to notifs --------- Co-authored-by: Paul Frazee <pfrazee@gmail.com>
Diffstat (limited to 'src/state/queries/notifications/feed.ts')
-rw-r--r-- | src/state/queries/notifications/feed.ts | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/src/state/queries/notifications/feed.ts b/src/state/queries/notifications/feed.ts index d2c150c31..3f9700c79 100644 --- a/src/state/queries/notifications/feed.ts +++ b/src/state/queries/notifications/feed.ts @@ -16,6 +16,7 @@ * 3. Don't call this query's `refetch()` if you're trying to sync latest; call `checkUnread()` instead. */ +import {useEffect} from 'react' import {AppBskyFeedDefs} from '@atproto/api' import { useInfiniteQuery, @@ -49,7 +50,7 @@ export function useNotificationFeedQuery(opts?: {enabled?: boolean}) { const unreads = useUnreadNotificationsApi() const enabled = opts?.enabled !== false - return useInfiniteQuery< + const query = useInfiniteQuery< FeedPage, Error, InfiniteData<FeedPage>, @@ -85,6 +86,21 @@ export function useNotificationFeedQuery(opts?: {enabled?: boolean}) { getNextPageParam: lastPage => lastPage.cursor, enabled, }) + + useEffect(() => { + const {isFetching, hasNextPage, data} = query + + let count = 0 + for (const page of data?.pages || []) { + count += page.items.length + } + + if (!isFetching && hasNextPage && count < PAGE_SIZE) { + query.fetchNextPage() + } + }, [query]) + + return query } /** |