#69 : Fix for non infinite case

This commit is contained in:
Vadim
2021-09-08 19:26:04 +03:00
parent b8e2e57426
commit 6cc9e12971
2 changed files with 22 additions and 10 deletions

View File

@@ -2,15 +2,10 @@ export function getNextPageIndexLimited({
currentPageIndex,
pagesCount,
pagesToScroll,
clonesCountTail,
}) {
if (pagesCount < 1) throw new Error('pagesCount must be at least 1')
return Math.min(
Math.max(currentPageIndex +
Math.min(pagesCount - clonesCountTail - currentPageIndex, pagesToScroll),
0),
pagesCount - 1
)
console.log('next', pagesCount, currentPageIndex, pagesCount - currentPageIndex)
return currentPageIndex + Math.min(pagesCount - (currentPageIndex+1) - pagesToScroll, pagesToScroll)
}
export function getNextPageIndexInfinte({
@@ -160,7 +155,7 @@ export function getCurrentPageIndexWithoutClones({
if (currentPageIndex === 0) return pagesCount - headClonesCount
return Math.floor((currentPageIndex - headClonesCount) / pagesToScroll)
}
return currentPageIndex
return Math.ceil(currentPageIndex / pagesToScroll)
}
export function getPagesCountWithoutClones({
@@ -214,3 +209,13 @@ export function getPartialPageSize({
_pages += pagesToShow + overlap
}
}
export function getScrollsCount({
infinite,
pagesCountWithoutClones,
pagesToScroll,
}) {
return infinite
? Math.ceil(pagesCountWithoutClones / pagesToScroll)
: Math.round(pagesCountWithoutClones / pagesToScroll)
}