1
0
mirror of https://github.com/tooot-app/app synced 2025-06-05 22:19:13 +02:00

Load less per page

This commit is contained in:
xmflsct
2023-02-16 20:42:16 +01:00
parent 86e7edb963
commit 718870e3e9
5 changed files with 102 additions and 89 deletions

View File

@ -156,10 +156,22 @@ const TimelineRefresh: React.FC<Props> = ({
>(queryKey, old => {
if (!old) return old
let count = 0
const keepPagesCount = Math.max(
1,
old.pages.findIndex(page => {
count = count + page.body.length
return count >= 20
})
)
prevCache.current = res.body.slice(0, -PREV_PER_BATCH)
return {
...old,
pages: [{ ...res, body: res.body.slice(-PREV_PER_BATCH) }, ...old.pages]
pages: [
{ ...res, body: res.body.slice(-PREV_PER_BATCH) },
...old.pages.slice(0, keepPagesCount)
],
pageParams: [{}, ...old.pageParams.slice(0, keepPagesCount)]
}
})