diff --git a/src/screens/Feeds/VibeScreen.tsx b/src/screens/Feeds/VibeScreen.tsx index 02241f8490..e6c0170c34 100644 --- a/src/screens/Feeds/VibeScreen.tsx +++ b/src/screens/Feeds/VibeScreen.tsx @@ -24,13 +24,15 @@ import { import {msg, Trans} from '@lingui/macro' import {useLingui} from '@lingui/react' import { + RouteProp, useFocusEffect, useIsFocused, useNavigation, + useRoute, } from '@react-navigation/native' import {NativeStackScreenProps} from '@react-navigation/native-stack' -import {HITSLOP_20, VIBES_FEED_URI} from '#/lib/constants' +import {HITSLOP_20} from '#/lib/constants' import {useNonReactiveCallback} from '#/lib/hooks/useNonReactiveCallback' import {CommonNavigatorParams, NavigationProp} from '#/lib/routes/types' import {sanitizeDisplayName} from '#/lib/strings/display-names' @@ -107,6 +109,7 @@ export function VibeScreen({}: Props) { } function YoloFeed() { + const {params} = useRoute>() const isFocused = useIsFocused() const { data, @@ -115,7 +118,9 @@ function YoloFeed() { hasNextPage, isFetchingNextPage, fetchNextPage, - } = usePostFeedQuery(`feedgen|${VIBES_FEED_URI}`) + } = usePostFeedQuery(`feedgen|${params.feedUri}`, { + initialCursor: params.cursor, + }) const videos = data?.pages.flatMap(page => page.slices.flatMap(slice => slice.items), diff --git a/src/state/queries/post-feed.ts b/src/state/queries/post-feed.ts index 2eb604627e..35062ebef9 100644 --- a/src/state/queries/post-feed.ts +++ b/src/state/queries/post-feed.ts @@ -61,9 +61,10 @@ export type FeedDescriptor = export interface FeedParams { mergeFeedEnabled?: boolean mergeFeedSources?: string[] + initialCursor?: string } -type RQPageParam = {cursor: string | undefined; api: FeedAPI} | undefined +type RQPageParam = {cursor: string | undefined; api?: FeedAPI} | undefined export const RQKEY_ROOT = 'post-feed' export function RQKEY(feedDesc: FeedDescriptor, params?: FeedParams) { @@ -171,24 +172,24 @@ export function usePostFeedQuery( queryKey: RQKEY(feedDesc, params), async queryFn({pageParam}: {pageParam: RQPageParam}) { logger.debug('usePostFeedQuery', {feedDesc, cursor: pageParam?.cursor}) - const {api, cursor} = pageParam - ? pageParam - : { - api: createApi({ - feedDesc, - feedParams: params || {}, - feedTuners, - agent, - // Not in the query key because they don't change: - userInterests, - // Not in the query key. Reacting to it switching isn't important: - enableFollowingToDiscoverFallback, - }), - cursor: undefined, - } + console.log('PAGE', feedDesc, pageParam?.cursor) + const cursor = pageParam?.cursor + let api = pageParam?.api + if (!api) { + api = createApi({ + feedDesc, + feedParams: params || {}, + feedTuners, + agent, + // Not in the query key because they don't change: + userInterests, + // Not in the query key. Reacting to it switching isn't important: + enableFollowingToDiscoverFallback, + }) + } try { - const res = await api.fetch({cursor, limit: fetchLimit}) + const res = await api!.fetch({cursor, limit: fetchLimit}) /* * If this is a public view, we need to check if posts fail moderation. @@ -223,7 +224,7 @@ export function usePostFeedQuery( throw e } }, - initialPageParam: undefined, + initialPageParam: {api: undefined, cursor: params?.initialCursor}, getNextPageParam: lastPage => lastPage.cursor ? {