Skip to content

Commit

Permalink
refact(kotti-pagination): inline function that calculates center of s…
Browse files Browse the repository at this point in the history
…hown number array
  • Loading branch information
Isokaeder committed Oct 14, 2021
1 parent 83d1d59 commit b1642f2
Showing 1 changed file with 7 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,14 @@ export default defineComponent<{
return baseElementsWidth + BASE_OFFSET * 2 + adjacentPagesOffset
})
const neighborValueCenter = computed(() => {
if (props.currentPage - props.adjacentAmount < 1)
return props.adjacentAmount + 1
if (props.currentPage + props.adjacentAmount > props.maximumPage - 2)
return props.maximumPage - props.adjacentAmount - 1
return props.currentPage
})
const neighborValues = computed(() => {
const center = neighborValueCenter.value
const center = ((): number => {
if (props.currentPage - props.adjacentAmount < 1)
return props.adjacentAmount + 1
if (props.currentPage + props.adjacentAmount > props.maximumPage - 2)
return props.maximumPage - props.adjacentAmount - 1
return props.currentPage
})()
const start = Math.max(0, center - props.adjacentAmount)
const end = Math.min(props.maximumPage, center + props.adjacentAmount)
return range(start, end + 1)
Expand Down

0 comments on commit b1642f2

Please sign in to comment.