@@ -29,36 +29,35 @@ export const buildPagedList = (
29
29
numPages : number ,
30
30
activePage : number ,
31
31
) : ( "left" | "right" | number ) [ ] => {
32
- if ( numPages > TOTAL_PAGE_BLOCKS ) {
33
- let pages = [ ] ;
34
- const leftBound = activePage - PAGE_NEIGHBORS ;
35
- const rightBound = activePage + PAGE_NEIGHBORS ;
36
- const beforeLastPage = numPages - 1 ;
37
- const startPage = leftBound > 2 ? leftBound : 2 ;
38
- const endPage = rightBound < beforeLastPage ? rightBound : beforeLastPage ;
32
+ if ( numPages <= TOTAL_PAGE_BLOCKS ) {
33
+ return range ( 1 , numPages ) ;
34
+ }
39
35
40
- pages = range ( startPage , endPage ) ;
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 ;
41
41
42
- const singleSpillOffset = PAGES_TO_DISPLAY - pages . length - 1 ;
43
- const hasLeftOverflow = startPage > 2 ;
44
- const hasRightOverflow = endPage < beforeLastPage ;
45
- const leftOverflowPage = "left" as const ;
46
- const rightOverflowPage = "right" as const ;
42
+ let pages : ReturnType < typeof buildPagedList > = range ( startPage , endPage ) ;
47
43
48
- if ( hasLeftOverflow && ! hasRightOverflow ) {
49
- const extraPages = range ( startPage - singleSpillOffset , startPage - 1 ) ;
50
- pages = [ leftOverflowPage , ...extraPages , ...pages ] ;
51
- } else if ( ! hasLeftOverflow && hasRightOverflow ) {
52
- const extraPages = range ( endPage + 1 , endPage + singleSpillOffset ) ;
53
- pages = [ ...pages , ...extraPages , rightOverflowPage ] ;
54
- } else if ( hasLeftOverflow && hasRightOverflow ) {
55
- pages = [ leftOverflowPage , ...pages , rightOverflowPage ] ;
56
- }
44
+ const singleSpillOffset = PAGES_TO_DISPLAY - pages . length - 1 ;
45
+ const hasLeftOverflow = startPage > 2 ;
46
+ const hasRightOverflow = endPage < beforeLastPage ;
47
+ const leftOverflowPage = "left" ;
48
+ const rightOverflowPage = "right" ;
57
49
58
- return [ 1 , ...pages , numPages ] ;
50
+ if ( hasLeftOverflow && ! hasRightOverflow ) {
51
+ const extraPages = range ( startPage - singleSpillOffset , startPage - 1 ) ;
52
+ pages = [ leftOverflowPage , ...extraPages , ...pages ] ;
53
+ } else if ( ! hasLeftOverflow && hasRightOverflow ) {
54
+ const extraPages = range ( endPage + 1 , endPage + singleSpillOffset ) ;
55
+ pages = [ ...pages , ...extraPages , rightOverflowPage ] ;
56
+ } else if ( hasLeftOverflow && hasRightOverflow ) {
57
+ pages = [ leftOverflowPage , ...pages , rightOverflowPage ] ;
59
58
}
60
59
61
- return range ( 1 , numPages ) ;
60
+ return [ 1 , ... pages , numPages ] ;
62
61
} ;
63
62
64
63
/**
0 commit comments