@@ -24,6 +24,24 @@ export function lastPage(data: Data, page_size: number) {
24
24
return Math . max ( Math . ceil ( data . length / page_size ) - 1 , 0 ) ;
25
25
}
26
26
27
+ export function loadPrevious ( page_current : number , setProps : SetProps ) {
28
+ if ( page_current <= 0 ) {
29
+ return ;
30
+ }
31
+
32
+ page_current -- ;
33
+ setProps ( { page_current, ...clearSelection } ) ;
34
+ }
35
+
36
+ export function loadFirst ( page_current : number , setProps : SetProps ) {
37
+ page_current = 0 ;
38
+ setProps ( { page_current, ...clearSelection } ) ;
39
+ }
40
+
41
+ export function hasPrevious ( page_current : number ) {
42
+ return ( page_current !== 0 ) ;
43
+ }
44
+
27
45
function getBackEndPagination (
28
46
page_current : number ,
29
47
setProps : SetProps ,
@@ -40,18 +58,8 @@ function getBackEndPagination(
40
58
page_current ++ ;
41
59
setProps ( { page_current, ...clearSelection } ) ;
42
60
} ,
43
- loadPrevious : ( ) => {
44
- if ( page_current <= 0 ) {
45
- return ;
46
- }
47
-
48
- page_current -- ;
49
- setProps ( { page_current, ...clearSelection } ) ;
50
- } ,
51
- loadFirst : ( ) => {
52
- page_current = 0 ;
53
- setProps ( { page_current, ...clearSelection } ) ;
54
- } ,
61
+ loadPrevious : ( ) => loadPrevious ( page_current , setProps ) ,
62
+ loadFirst : ( ) => loadFirst ( page_current , setProps ) ,
55
63
loadLast : ( ) => {
56
64
if ( page_count ) {
57
65
page_current = page_count ;
@@ -76,9 +84,7 @@ function getBackEndPagination(
76
84
77
85
setProps ( { page_current, ...clearSelection } ) ;
78
86
} ,
79
- hasPrevious : ( ) => {
80
- return page_current !== 0 ;
81
- } ,
87
+ hasPrevious : ( ) => hasPrevious ( page_current ) ,
82
88
hasNext : ( ) => {
83
89
return page_count === undefined || page_current !== page_count ;
84
90
} ,
@@ -105,18 +111,8 @@ function getFrontEndPagination(
105
111
page_current ++ ;
106
112
setProps ( { page_current, ...clearSelection } ) ;
107
113
} ,
108
- loadPrevious : ( ) => {
109
- if ( page_current <= 0 ) {
110
- return ;
111
- }
112
-
113
- page_current -- ;
114
- setProps ( { page_current, ...clearSelection } ) ;
115
- } ,
116
- loadFirst : ( ) => {
117
- page_current = 0 ;
118
- setProps ( { page_current, ...clearSelection } ) ;
119
- } ,
114
+ loadPrevious : ( ) => loadPrevious ( page_current , setProps ) ,
115
+ loadFirst : ( ) => loadFirst ( page_current , setProps ) ,
120
116
loadLast : ( ) => {
121
117
page_current = lastPage ( data , page_size ) ;
122
118
setProps ( { page_current, ...clearSelection } ) ;
@@ -138,9 +134,7 @@ function getFrontEndPagination(
138
134
139
135
setProps ( { page_current, ...clearSelection } ) ;
140
136
} ,
141
- hasPrevious : ( ) => {
142
- return ( page_current !== 0 ) ;
143
- } ,
137
+ hasPrevious : ( ) => hasPrevious ( page_current ) ,
144
138
hasNext : ( ) => {
145
139
return ( page_current !== lastPage ( data , page_size ) ) ;
146
140
} ,
0 commit comments