Fix lag when switching tabs (#2046)

zio/stable
dan 2023-11-30 19:57:54 +00:00 committed by GitHub
parent fcd22d4ccb
commit cb193a827d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 43 additions and 38 deletions

View File

@ -1,3 +1,4 @@
import {useCallback} from 'react'
import {AppBskyFeedDefs, AppBskyFeedPost, moderatePost} from '@atproto/api' import {AppBskyFeedDefs, AppBskyFeedPost, moderatePost} from '@atproto/api'
import { import {
useInfiniteQuery, useInfiniteQuery,
@ -130,46 +131,50 @@ export function usePostFeedQuery(
api: lastPage.api, api: lastPage.api,
cursor: lastPage.cursor, cursor: lastPage.cursor,
}), }),
select(data) { select: useCallback(
const tuner = params?.disableTuner (data: InfiniteData<FeedPageUnselected, RQPageParam>) => {
? new NoopFeedTuner() const tuner = params?.disableTuner
: new FeedTuner(feedTuners) ? new NoopFeedTuner()
return { : new FeedTuner(feedTuners)
pageParams: data.pageParams, return {
pages: data.pages.map(page => ({ pageParams: data.pageParams,
api: page.api, pages: data.pages.map(page => ({
tuner, api: page.api,
cursor: page.cursor, tuner,
slices: tuner.tune(page.feed).map(slice => ({ cursor: page.cursor,
_reactKey: slice._reactKey, slices: tuner.tune(page.feed).map(slice => ({
rootUri: slice.rootItem.post.uri, _reactKey: slice._reactKey,
isThread: rootUri: slice.rootItem.post.uri,
slice.items.length > 1 && isThread:
slice.items.every( slice.items.length > 1 &&
item => item.post.author.did === slice.items[0].post.author.did, slice.items.every(
), item =>
items: slice.items item.post.author.did === slice.items[0].post.author.did,
.map((item, i) => { ),
if ( items: slice.items
AppBskyFeedPost.isRecord(item.post.record) && .map((item, i) => {
AppBskyFeedPost.validateRecord(item.post.record).success if (
) { AppBskyFeedPost.isRecord(item.post.record) &&
return { AppBskyFeedPost.validateRecord(item.post.record).success
_reactKey: `${slice._reactKey}-${i}`, ) {
uri: item.post.uri, return {
post: item.post, _reactKey: `${slice._reactKey}-${i}`,
record: item.post.record, uri: item.post.uri,
reason: post: item.post,
i === 0 && slice.source ? slice.source : item.reason, record: item.post.record,
reason:
i === 0 && slice.source ? slice.source : item.reason,
}
} }
} return undefined
return undefined })
}) .filter(Boolean) as FeedPostSliceItem[],
.filter(Boolean) as FeedPostSliceItem[], })),
})), })),
})), }
} },
}, [feedTuners, params?.disableTuner],
),
}) })
} }