@@ -141,21 +141,11 @@ export class Pagination extends LitElement {
141
141
142
142
searchParams = new SearchParamsController ( this , ( params ) => {
143
143
const page = parsePage ( params . get ( this . name ) ) ;
144
-
145
- // TODO: figure out why previous params aren't working here
146
- // in the meantime, 0 works okay — we do an inequality check in `onPageChange` anyways
147
- this . onPageChange ( page , 0 ) ;
144
+ this . onPageChange ( page ) ;
148
145
} ) ;
149
146
150
- // @property ({ type: Number })
151
- // public set page(page: number) {
152
- // this.onPageChange(page);
153
- // }
154
-
155
- public get page ( ) {
156
- const page = parsePage ( this . searchParams . searchParams . get ( this . name ) ) ;
157
- return Math . max ( 1 , Math . min ( this . pages , page ) ) ;
158
- }
147
+ @state ( )
148
+ page = 1 ;
159
149
160
150
@property ( { type : String } )
161
151
name = "page" ;
@@ -188,9 +178,10 @@ export class Pagination extends LitElement {
188
178
const parsedPage = parseFloat (
189
179
this . searchParams . searchParams . get ( this . name ) ?? "1" ,
190
180
) ;
191
- if ( parsedPage > this . pages || parsedPage < 1 || parsedPage % 1 !== 0 ) {
192
- this . onPageChange ( this . page , parsedPage ) ;
193
- this . requestUpdate ( "page" , parsedPage ) ;
181
+ if ( parsedPage != this . page ) {
182
+ const page = parsePage ( this . searchParams . searchParams . get ( this . name ) ) ;
183
+ const constrainedPage = Math . max ( 1 , Math . min ( this . pages , page ) ) ;
184
+ this . onPageChange ( constrainedPage ) ;
194
185
}
195
186
196
187
if ( changedProperties . get ( "page" ) && this . page ) {
@@ -354,8 +345,8 @@ export class Pagination extends LitElement {
354
345
this . onPageChange ( this . page < this . pages ? this . page + 1 : this . pages ) ;
355
346
}
356
347
357
- private onPageChange ( page : number , prevPage = this . page ) {
358
- if ( prevPage !== page ) {
348
+ private onPageChange ( page : number ) {
349
+ if ( this . page !== page ) {
359
350
this . searchParams . set ( ( params ) => {
360
351
if ( page === 1 ) {
361
352
params . delete ( this . name ) ;
@@ -364,14 +355,14 @@ export class Pagination extends LitElement {
364
355
}
365
356
return params ;
366
357
} ) ;
367
- this . requestUpdate ( "page" , prevPage ) ;
368
358
this . dispatchEvent (
369
359
new CustomEvent < PageChangeDetail > ( "page-change" , {
370
360
detail : { page : page , pages : this . pages } ,
371
361
composed : true ,
372
362
} ) ,
373
363
) ;
374
364
}
365
+ this . page = page ;
375
366
}
376
367
377
368
private calculatePages ( ) {
0 commit comments