Fetch more than 3 suggested follows after first load (#4595)
* Fetch more than 3 sugg follows after first load * Preview handling via overfetchingzio/stable
parent
55812b0394
commit
cb37647949
|
@ -34,13 +34,14 @@ const suggestedFollowsByActorQueryKey = (did: string) => [
|
||||||
did,
|
did,
|
||||||
]
|
]
|
||||||
|
|
||||||
type SuggestedFollowsOptions = {limit?: number}
|
type SuggestedFollowsOptions = {limit?: number; subsequentPageLimit?: number}
|
||||||
|
|
||||||
export function useSuggestedFollowsQuery(options?: SuggestedFollowsOptions) {
|
export function useSuggestedFollowsQuery(options?: SuggestedFollowsOptions) {
|
||||||
const {currentAccount} = useSession()
|
const {currentAccount} = useSession()
|
||||||
const agent = useAgent()
|
const agent = useAgent()
|
||||||
const moderationOpts = useModerationOpts()
|
const moderationOpts = useModerationOpts()
|
||||||
const {data: preferences} = usePreferencesQuery()
|
const {data: preferences} = usePreferencesQuery()
|
||||||
|
const limit = options?.limit || 25
|
||||||
|
|
||||||
return useInfiniteQuery<
|
return useInfiniteQuery<
|
||||||
AppBskyActorGetSuggestions.OutputSchema,
|
AppBskyActorGetSuggestions.OutputSchema,
|
||||||
|
@ -54,9 +55,13 @@ export function useSuggestedFollowsQuery(options?: SuggestedFollowsOptions) {
|
||||||
queryKey: suggestedFollowsQueryKey(options),
|
queryKey: suggestedFollowsQueryKey(options),
|
||||||
queryFn: async ({pageParam}) => {
|
queryFn: async ({pageParam}) => {
|
||||||
const contentLangs = getContentLanguages().join(',')
|
const contentLangs = getContentLanguages().join(',')
|
||||||
|
const maybeDifferentLimit =
|
||||||
|
options?.subsequentPageLimit && pageParam
|
||||||
|
? options.subsequentPageLimit
|
||||||
|
: limit
|
||||||
const res = await agent.app.bsky.actor.getSuggestions(
|
const res = await agent.app.bsky.actor.getSuggestions(
|
||||||
{
|
{
|
||||||
limit: options?.limit || 25,
|
limit: maybeDifferentLimit,
|
||||||
cursor: pageParam,
|
cursor: pageParam,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -282,7 +282,7 @@ export function Explore() {
|
||||||
isFetchingNextPage: isFetchingNextProfilesPage,
|
isFetchingNextPage: isFetchingNextProfilesPage,
|
||||||
error: profilesError,
|
error: profilesError,
|
||||||
fetchNextPage: fetchNextProfilesPage,
|
fetchNextPage: fetchNextProfilesPage,
|
||||||
} = useSuggestedFollowsQuery({limit: 3})
|
} = useSuggestedFollowsQuery({limit: 6, subsequentPageLimit: 10})
|
||||||
const {
|
const {
|
||||||
data: feeds,
|
data: feeds,
|
||||||
hasNextPage: hasNextFeedsPage,
|
hasNextPage: hasNextFeedsPage,
|
||||||
|
@ -290,7 +290,7 @@ export function Explore() {
|
||||||
isFetchingNextPage: isFetchingNextFeedsPage,
|
isFetchingNextPage: isFetchingNextFeedsPage,
|
||||||
error: feedsError,
|
error: feedsError,
|
||||||
fetchNextPage: fetchNextFeedsPage,
|
fetchNextPage: fetchNextFeedsPage,
|
||||||
} = useGetPopularFeedsQuery({limit: 3})
|
} = useGetPopularFeedsQuery({limit: 10})
|
||||||
|
|
||||||
const isLoadingMoreProfiles = isFetchingNextProfilesPage && !isLoadingProfiles
|
const isLoadingMoreProfiles = isFetchingNextProfilesPage && !isLoadingProfiles
|
||||||
const onLoadMoreProfiles = React.useCallback(async () => {
|
const onLoadMoreProfiles = React.useCallback(async () => {
|
||||||
|
@ -340,11 +340,12 @@ export function Explore() {
|
||||||
// Currently the responses contain duplicate items.
|
// Currently the responses contain duplicate items.
|
||||||
// Needs to be fixed on backend, but let's dedupe to be safe.
|
// Needs to be fixed on backend, but let's dedupe to be safe.
|
||||||
let seen = new Set()
|
let seen = new Set()
|
||||||
|
const profileItems: ExploreScreenItems[] = []
|
||||||
for (const page of profiles.pages) {
|
for (const page of profiles.pages) {
|
||||||
for (const actor of page.actors) {
|
for (const actor of page.actors) {
|
||||||
if (!seen.has(actor.did)) {
|
if (!seen.has(actor.did)) {
|
||||||
seen.add(actor.did)
|
seen.add(actor.did)
|
||||||
i.push({
|
profileItems.push({
|
||||||
type: 'profile',
|
type: 'profile',
|
||||||
key: actor.did,
|
key: actor.did,
|
||||||
profile: actor,
|
profile: actor,
|
||||||
|
@ -354,13 +355,19 @@ export function Explore() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasNextProfilesPage) {
|
if (hasNextProfilesPage) {
|
||||||
|
// splice off 3 as previews if we have a next page
|
||||||
|
const previews = profileItems.splice(-3)
|
||||||
|
// push remainder
|
||||||
|
i.push(...profileItems)
|
||||||
i.push({
|
i.push({
|
||||||
type: 'loadMore',
|
type: 'loadMore',
|
||||||
key: 'loadMoreProfiles',
|
key: 'loadMoreProfiles',
|
||||||
isLoadingMore: isLoadingMoreProfiles,
|
isLoadingMore: isLoadingMoreProfiles,
|
||||||
onLoadMore: onLoadMoreProfiles,
|
onLoadMore: onLoadMoreProfiles,
|
||||||
items: i.filter(item => item.type === 'profile').slice(-3),
|
items: previews,
|
||||||
})
|
})
|
||||||
|
} else {
|
||||||
|
i.push(...profileItems)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (profilesError) {
|
if (profilesError) {
|
||||||
|
@ -390,11 +397,12 @@ export function Explore() {
|
||||||
// Currently the responses contain duplicate items.
|
// Currently the responses contain duplicate items.
|
||||||
// Needs to be fixed on backend, but let's dedupe to be safe.
|
// Needs to be fixed on backend, but let's dedupe to be safe.
|
||||||
let seen = new Set()
|
let seen = new Set()
|
||||||
|
const feedItems: ExploreScreenItems[] = []
|
||||||
for (const page of feeds.pages) {
|
for (const page of feeds.pages) {
|
||||||
for (const feed of page.feeds) {
|
for (const feed of page.feeds) {
|
||||||
if (!seen.has(feed.uri)) {
|
if (!seen.has(feed.uri)) {
|
||||||
seen.add(feed.uri)
|
seen.add(feed.uri)
|
||||||
i.push({
|
feedItems.push({
|
||||||
type: 'feed',
|
type: 'feed',
|
||||||
key: feed.uri,
|
key: feed.uri,
|
||||||
feed,
|
feed,
|
||||||
|
@ -403,6 +411,7 @@ export function Explore() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// feeds errors can occur during pagination, so feeds is truthy
|
||||||
if (feedsError) {
|
if (feedsError) {
|
||||||
i.push({
|
i.push({
|
||||||
type: 'error',
|
type: 'error',
|
||||||
|
@ -418,13 +427,17 @@ export function Explore() {
|
||||||
error: cleanError(preferencesError),
|
error: cleanError(preferencesError),
|
||||||
})
|
})
|
||||||
} else if (hasNextFeedsPage) {
|
} else if (hasNextFeedsPage) {
|
||||||
|
const preview = feedItems.splice(-3)
|
||||||
|
i.push(...feedItems)
|
||||||
i.push({
|
i.push({
|
||||||
type: 'loadMore',
|
type: 'loadMore',
|
||||||
key: 'loadMoreFeeds',
|
key: 'loadMoreFeeds',
|
||||||
isLoadingMore: isLoadingMoreFeeds,
|
isLoadingMore: isLoadingMoreFeeds,
|
||||||
onLoadMore: onLoadMoreFeeds,
|
onLoadMore: onLoadMoreFeeds,
|
||||||
items: i.filter(item => item.type === 'feed').slice(-3),
|
items: preview,
|
||||||
})
|
})
|
||||||
|
} else {
|
||||||
|
i.push(...feedItems)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (feedsError) {
|
if (feedsError) {
|
||||||
|
|
Loading…
Reference in New Issue