#69 : Fix for non infinite case
This commit is contained in:
@@ -22,6 +22,7 @@
|
|||||||
getPagesCountWithoutClones,
|
getPagesCountWithoutClones,
|
||||||
getClonesCount,
|
getClonesCount,
|
||||||
getPartialPageSize,
|
getPartialPageSize,
|
||||||
|
getScrollsCount,
|
||||||
} from '../../utils/page'
|
} from '../../utils/page'
|
||||||
import { get } from '../../utils/object'
|
import { get } from '../../utils/object'
|
||||||
import { ProgressManager } from '../../utils/ProgressManager'
|
import { ProgressManager } from '../../utils/ProgressManager'
|
||||||
@@ -152,7 +153,11 @@
|
|||||||
|
|
||||||
let pagesCount = 0
|
let pagesCount = 0
|
||||||
let pagesCountWithoutClones = 1
|
let pagesCountWithoutClones = 1
|
||||||
$: scrollsCount = Math.ceil(pagesCountWithoutClones / pagesToScroll)
|
$: scrollsCount = getScrollsCount({
|
||||||
|
infinite,
|
||||||
|
pagesCountWithoutClones,
|
||||||
|
pagesToScroll,
|
||||||
|
})
|
||||||
|
|
||||||
let partialPageSize = 0
|
let partialPageSize = 0
|
||||||
|
|
||||||
@@ -334,6 +339,7 @@
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
async function showPrevPage(options) {
|
async function showPrevPage(options) {
|
||||||
|
// TODO: return if disabled
|
||||||
await changePage(
|
await changePage(
|
||||||
() => store.prev({
|
() => store.prev({
|
||||||
infinite,
|
infinite,
|
||||||
@@ -344,6 +350,7 @@
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
async function showNextPage(options) {
|
async function showNextPage(options) {
|
||||||
|
// TODO: return if disabled
|
||||||
await changePage(
|
await changePage(
|
||||||
() => store.next({
|
() => store.next({
|
||||||
infinite,
|
infinite,
|
||||||
@@ -436,7 +443,7 @@
|
|||||||
<div class="sc-carousel__arrow-container">
|
<div class="sc-carousel__arrow-container">
|
||||||
<Arrow
|
<Arrow
|
||||||
direction="next"
|
direction="next"
|
||||||
disabled={!infinite && currentPageIndexWithoutClones === pagesCountWithoutClones - 1}
|
disabled={!infinite && currentPageIndexWithoutClones === scrollsCount - 1}
|
||||||
on:click={showNextPage}
|
on:click={showNextPage}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -2,15 +2,10 @@ export function getNextPageIndexLimited({
|
|||||||
currentPageIndex,
|
currentPageIndex,
|
||||||
pagesCount,
|
pagesCount,
|
||||||
pagesToScroll,
|
pagesToScroll,
|
||||||
clonesCountTail,
|
|
||||||
}) {
|
}) {
|
||||||
if (pagesCount < 1) throw new Error('pagesCount must be at least 1')
|
if (pagesCount < 1) throw new Error('pagesCount must be at least 1')
|
||||||
return Math.min(
|
console.log('next', pagesCount, currentPageIndex, pagesCount - currentPageIndex)
|
||||||
Math.max(currentPageIndex +
|
return currentPageIndex + Math.min(pagesCount - (currentPageIndex+1) - pagesToScroll, pagesToScroll)
|
||||||
Math.min(pagesCount - clonesCountTail - currentPageIndex, pagesToScroll),
|
|
||||||
0),
|
|
||||||
pagesCount - 1
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getNextPageIndexInfinte({
|
export function getNextPageIndexInfinte({
|
||||||
@@ -160,7 +155,7 @@ export function getCurrentPageIndexWithoutClones({
|
|||||||
if (currentPageIndex === 0) return pagesCount - headClonesCount
|
if (currentPageIndex === 0) return pagesCount - headClonesCount
|
||||||
return Math.floor((currentPageIndex - headClonesCount) / pagesToScroll)
|
return Math.floor((currentPageIndex - headClonesCount) / pagesToScroll)
|
||||||
}
|
}
|
||||||
return currentPageIndex
|
return Math.ceil(currentPageIndex / pagesToScroll)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getPagesCountWithoutClones({
|
export function getPagesCountWithoutClones({
|
||||||
@@ -214,3 +209,13 @@ export function getPartialPageSize({
|
|||||||
_pages += pagesToShow + overlap
|
_pages += pagesToShow + overlap
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getScrollsCount({
|
||||||
|
infinite,
|
||||||
|
pagesCountWithoutClones,
|
||||||
|
pagesToScroll,
|
||||||
|
}) {
|
||||||
|
return infinite
|
||||||
|
? Math.ceil(pagesCountWithoutClones / pagesToScroll)
|
||||||
|
: Math.round(pagesCountWithoutClones / pagesToScroll)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user