@@ -33,28 +33,24 @@ export const buildPagedList = (
33
33
return range ( 1 , numPages ) ;
34
34
}
35
35
36
- const leftBound = activePage - PAGE_NEIGHBORS ;
37
- const rightBound = activePage + PAGE_NEIGHBORS ;
38
- const beforeLastPage = numPages - 1 ;
39
- const startPage = leftBound > 2 ? leftBound : 2 ;
40
- const endPage = rightBound < beforeLastPage ? rightBound : beforeLastPage ;
36
+ const pageBeforeLast = numPages - 1 ;
37
+ const startPage = Math . max ( activePage - PAGE_NEIGHBORS , 2 ) ;
38
+ const endPage = Math . min ( activePage + PAGE_NEIGHBORS , pageBeforeLast ) ;
41
39
42
40
let pages : ReturnType < typeof buildPagedList > = range ( startPage , endPage ) ;
43
41
44
42
const singleSpillOffset = PAGES_TO_DISPLAY - pages . length - 1 ;
45
43
const hasLeftOverflow = startPage > 2 ;
46
- const hasRightOverflow = endPage < beforeLastPage ;
47
- const leftOverflowPage = "left" ;
48
- const rightOverflowPage = "right" ;
44
+ const hasRightOverflow = endPage < pageBeforeLast ;
49
45
50
46
if ( hasLeftOverflow && ! hasRightOverflow ) {
51
47
const extraPages = range ( startPage - singleSpillOffset , startPage - 1 ) ;
52
- pages = [ leftOverflowPage , ...extraPages , ...pages ] ;
48
+ pages = [ "left" , ...extraPages , ...pages ] ;
53
49
} else if ( ! hasLeftOverflow && hasRightOverflow ) {
54
50
const extraPages = range ( endPage + 1 , endPage + singleSpillOffset ) ;
55
- pages = [ ...pages , ...extraPages , rightOverflowPage ] ;
51
+ pages = [ ...pages , ...extraPages , "right" ] ;
56
52
} else if ( hasLeftOverflow && hasRightOverflow ) {
57
- pages = [ leftOverflowPage , ...pages , rightOverflowPage ] ;
53
+ pages = [ "left" , ...pages , "right" ] ;
58
54
}
59
55
60
56
return [ 1 , ...pages , numPages ] ;
0 commit comments