From 3316de975e4b97a818bda3147396be576a15b9ea Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Thu, 16 Jan 2025 15:31:42 -0600 Subject: [PATCH] Partial revert, just filter posts to start at index --- src/components/VideoPostCard.tsx | 2 +- src/lib/routes/types.ts | 2 +- src/screens/Feeds/VibeScreen.tsx | 12 +++++++---- src/state/queries/post-feed.ts | 37 ++++++++++++++++---------------- 4 files changed, 28 insertions(+), 25 deletions(-) diff --git a/src/components/VideoPostCard.tsx b/src/components/VideoPostCard.tsx index 9a49add5b2..401771dd1b 100644 --- a/src/components/VideoPostCard.tsx +++ b/src/components/VideoPostCard.tsx @@ -54,7 +54,7 @@ export function VideoPostCard({ screen: 'TempVibe', params: { feedUri: sourceFeedUri, - cursor: post.cid, + postUri: post.uri, }, }} onHoverIn={onHoverIn} diff --git a/src/lib/routes/types.ts b/src/lib/routes/types.ts index ab23a331c1..85bfc923af 100644 --- a/src/lib/routes/types.ts +++ b/src/lib/routes/types.ts @@ -57,7 +57,7 @@ export type CommonNavigatorParams = { StarterPackShort: {code: string} StarterPackWizard: undefined StarterPackEdit: {rkey?: string} - TempVibe: {feedUri: string; cursor?: string} + TempVibe: {feedUri: string; postUri?: string} } export type BottomTabNavigatorParams = CommonNavigatorParams & { diff --git a/src/screens/Feeds/VibeScreen.tsx b/src/screens/Feeds/VibeScreen.tsx index e6c0170c34..050a6e0dab 100644 --- a/src/screens/Feeds/VibeScreen.tsx +++ b/src/screens/Feeds/VibeScreen.tsx @@ -118,13 +118,17 @@ function YoloFeed() { hasNextPage, isFetchingNextPage, fetchNextPage, - } = usePostFeedQuery(`feedgen|${params.feedUri}`, { - initialCursor: params.cursor, - }) + } = usePostFeedQuery(`feedgen|${params.feedUri}`) - const videos = data?.pages.flatMap(page => + let videos = data?.pages.flatMap(page => page.slices.flatMap(slice => slice.items), ) + const startingVideoIndex = videos?.findIndex(video => { + return video.post.uri === params.postUri + }) + if (videos && startingVideoIndex && startingVideoIndex > -1) { + videos = videos.slice(startingVideoIndex) + } const [currentSources, setCurrentSources] = useState< [string | null, string | null, string | null] diff --git a/src/state/queries/post-feed.ts b/src/state/queries/post-feed.ts index 35062ebef9..2eb604627e 100644 --- a/src/state/queries/post-feed.ts +++ b/src/state/queries/post-feed.ts @@ -61,10 +61,9 @@ 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) { @@ -172,24 +171,24 @@ export function usePostFeedQuery( queryKey: RQKEY(feedDesc, params), async queryFn({pageParam}: {pageParam: RQPageParam}) { logger.debug('usePostFeedQuery', {feedDesc, cursor: pageParam?.cursor}) - 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, - }) - } + 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, + } 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. @@ -224,7 +223,7 @@ export function usePostFeedQuery( throw e } }, - initialPageParam: {api: undefined, cursor: params?.initialCursor}, + initialPageParam: undefined, getNextPageParam: lastPage => lastPage.cursor ? {