1- import { useCallback , useMemo } from 'react'
1+ import { ReactNode , useCallback , useMemo } from 'react'
22
33import { ChevronLeft , ChevronRight } from 'react-feather'
44
5- import { ArrowButton , BlankButton , PageButton , PageButtonLink , PaginationBox } from './styled'
5+ import { PageNavigationButton } from './PageNavigationButton'
6+ import { BlankButton , PaginationBox } from './styled'
67
78const PAGES_LIMIT = 14
89
@@ -15,17 +16,14 @@ export interface OrdersTablePaginationProps {
1516 className ?: string
1617}
1718
18- // TODO: Break down this large function into smaller functions
19- // TODO: Add proper return type annotation
20- // eslint-disable-next-line max-lines-per-function, @typescript-eslint/explicit-function-return-type
2119export function OrdersTablePagination ( {
2220 pageSize,
2321 totalCount,
2422 currentPage,
2523 getPageUrl,
2624 onPageChange,
2725 className,
28- } : OrdersTablePaginationProps ) {
26+ } : OrdersTablePaginationProps ) : ReactNode {
2927 const pagesCount = Math . ceil ( totalCount / pageSize )
3028
3129 const pagesArray = useMemo ( ( ) => [ ...new Array ( pagesCount ) ] . map ( ( item , i ) => i ) , [ pagesCount ] )
@@ -42,12 +40,8 @@ export function OrdersTablePagination({
4240 ( page : number ) => {
4341 if ( onPageChange ) {
4442 onPageChange ( page )
45- return
46- }
47-
48- if ( getPageUrl ) {
43+ } else if ( getPageUrl ) {
4944 getPageUrl ( page )
50- return
5145 }
5246 } ,
5347 [ onPageChange , getPageUrl ] ,
@@ -57,12 +51,15 @@ export function OrdersTablePagination({
5751 < PaginationBox className = { className } >
5852 { isListBig && (
5953 < >
60- < ArrowButton onClick = { ( ) => goToPage ( Math . max ( currentPage - 1 , 1 ) ) } >
54+ < PageNavigationButton goToPage = { goToPage } getPageUrl = { getPageUrl } index = { Math . max ( currentPage - 1 , 1 ) } >
6155 < ChevronLeft size = { 20 } />
62- </ ArrowButton >
56+ </ PageNavigationButton >
57+
6358 { ! isFirstPagesBatch && (
6459 < >
65- < PageButton onClick = { ( ) => goToPage ( 1 ) } > 1</ PageButton >
60+ < PageNavigationButton goToPage = { goToPage } getPageUrl = { getPageUrl } index = { 1 } >
61+ 1
62+ </ PageNavigationButton >
6663 < BlankButton > ...</ BlankButton >
6764 </ >
6865 ) }
@@ -71,35 +68,35 @@ export function OrdersTablePagination({
7168 { pagesArray . slice ( batchStart , batchEnd ) . map ( ( i ) => {
7269 const index = i + 1
7370
74- if ( onPageChange ) {
75- return (
76- < PageButton key = { index } $active = { index === currentPage } onClick = { ( ) => onPageChange ( index ) } >
77- { index }
78- </ PageButton >
79- )
80- }
81-
82- if ( getPageUrl ) {
83- return (
84- < PageButtonLink key = { index } $active = { index === currentPage } to = { getPageUrl ( index ) } >
85- { index }
86- </ PageButtonLink >
87- )
88- }
89-
90- return null
71+ return (
72+ < PageNavigationButton
73+ key = { index }
74+ goToPage = { goToPage }
75+ getPageUrl = { getPageUrl }
76+ index = { index }
77+ active = { index === currentPage }
78+ >
79+ { index }
80+ </ PageNavigationButton >
81+ )
9182 } ) }
9283 { isListBig && (
9384 < >
9485 { ! isLastPagesBatch && (
9586 < >
9687 < BlankButton > ...</ BlankButton >
97- < PageButton onClick = { ( ) => goToPage ( pagesCount ) } > { pagesCount } </ PageButton >
88+ < PageNavigationButton goToPage = { goToPage } getPageUrl = { getPageUrl } index = { pagesCount } >
89+ { pagesCount }
90+ </ PageNavigationButton >
9891 </ >
9992 ) }
100- < ArrowButton onClick = { ( ) => goToPage ( Math . min ( currentPage + 1 , pagesCount ) ) } >
93+ < PageNavigationButton
94+ goToPage = { goToPage }
95+ getPageUrl = { getPageUrl }
96+ index = { Math . min ( currentPage + 1 , pagesCount ) }
97+ >
10198 < ChevronRight size = { 20 } />
102- </ ArrowButton >
99+ </ PageNavigationButton >
103100 </ >
104101 ) }
105102 </ PaginationBox >
0 commit comments