Bluesky app fork with some witchin' additions 💫
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Fetch more than 3 suggested follows after first load (#4595)

* Fetch more than 3 sugg follows after first load

* Preview handling via overfetching

authored by

Eric Bailey and committed by
GitHub
cb376479 55812b03

+26 -8
+7 -2
src/state/queries/suggested-follows.ts
··· 34 34 did, 35 35 ] 36 36 37 - type SuggestedFollowsOptions = {limit?: number} 37 + type SuggestedFollowsOptions = {limit?: number; subsequentPageLimit?: number} 38 38 39 39 export function useSuggestedFollowsQuery(options?: SuggestedFollowsOptions) { 40 40 const {currentAccount} = useSession() 41 41 const agent = useAgent() 42 42 const moderationOpts = useModerationOpts() 43 43 const {data: preferences} = usePreferencesQuery() 44 + const limit = options?.limit || 25 44 45 45 46 return useInfiniteQuery< 46 47 AppBskyActorGetSuggestions.OutputSchema, ··· 54 55 queryKey: suggestedFollowsQueryKey(options), 55 56 queryFn: async ({pageParam}) => { 56 57 const contentLangs = getContentLanguages().join(',') 58 + const maybeDifferentLimit = 59 + options?.subsequentPageLimit && pageParam 60 + ? options.subsequentPageLimit 61 + : limit 57 62 const res = await agent.app.bsky.actor.getSuggestions( 58 63 { 59 - limit: options?.limit || 25, 64 + limit: maybeDifferentLimit, 60 65 cursor: pageParam, 61 66 }, 62 67 {
+19 -6
src/view/screens/Search/Explore.tsx
··· 282 282 isFetchingNextPage: isFetchingNextProfilesPage, 283 283 error: profilesError, 284 284 fetchNextPage: fetchNextProfilesPage, 285 - } = useSuggestedFollowsQuery({limit: 3}) 285 + } = useSuggestedFollowsQuery({limit: 6, subsequentPageLimit: 10}) 286 286 const { 287 287 data: feeds, 288 288 hasNextPage: hasNextFeedsPage, ··· 290 290 isFetchingNextPage: isFetchingNextFeedsPage, 291 291 error: feedsError, 292 292 fetchNextPage: fetchNextFeedsPage, 293 - } = useGetPopularFeedsQuery({limit: 3}) 293 + } = useGetPopularFeedsQuery({limit: 10}) 294 294 295 295 const isLoadingMoreProfiles = isFetchingNextProfilesPage && !isLoadingProfiles 296 296 const onLoadMoreProfiles = React.useCallback(async () => { ··· 340 340 // Currently the responses contain duplicate items. 341 341 // Needs to be fixed on backend, but let's dedupe to be safe. 342 342 let seen = new Set() 343 + const profileItems: ExploreScreenItems[] = [] 343 344 for (const page of profiles.pages) { 344 345 for (const actor of page.actors) { 345 346 if (!seen.has(actor.did)) { 346 347 seen.add(actor.did) 347 - i.push({ 348 + profileItems.push({ 348 349 type: 'profile', 349 350 key: actor.did, 350 351 profile: actor, ··· 354 355 } 355 356 356 357 if (hasNextProfilesPage) { 358 + // splice off 3 as previews if we have a next page 359 + const previews = profileItems.splice(-3) 360 + // push remainder 361 + i.push(...profileItems) 357 362 i.push({ 358 363 type: 'loadMore', 359 364 key: 'loadMoreProfiles', 360 365 isLoadingMore: isLoadingMoreProfiles, 361 366 onLoadMore: onLoadMoreProfiles, 362 - items: i.filter(item => item.type === 'profile').slice(-3), 367 + items: previews, 363 368 }) 369 + } else { 370 + i.push(...profileItems) 364 371 } 365 372 } else { 366 373 if (profilesError) { ··· 390 397 // Currently the responses contain duplicate items. 391 398 // Needs to be fixed on backend, but let's dedupe to be safe. 392 399 let seen = new Set() 400 + const feedItems: ExploreScreenItems[] = [] 393 401 for (const page of feeds.pages) { 394 402 for (const feed of page.feeds) { 395 403 if (!seen.has(feed.uri)) { 396 404 seen.add(feed.uri) 397 - i.push({ 405 + feedItems.push({ 398 406 type: 'feed', 399 407 key: feed.uri, 400 408 feed, ··· 403 411 } 404 412 } 405 413 414 + // feeds errors can occur during pagination, so feeds is truthy 406 415 if (feedsError) { 407 416 i.push({ 408 417 type: 'error', ··· 418 427 error: cleanError(preferencesError), 419 428 }) 420 429 } else if (hasNextFeedsPage) { 430 + const preview = feedItems.splice(-3) 431 + i.push(...feedItems) 421 432 i.push({ 422 433 type: 'loadMore', 423 434 key: 'loadMoreFeeds', 424 435 isLoadingMore: isLoadingMoreFeeds, 425 436 onLoadMore: onLoadMoreFeeds, 426 - items: i.filter(item => item.type === 'feed').slice(-3), 437 + items: preview, 427 438 }) 439 + } else { 440 + i.push(...feedItems) 428 441 } 429 442 } else { 430 443 if (feedsError) {