Skip to content

Commit c3dc2c5

Browse files
committed
improve page validation & constraints, and update url when necessary
1 parent ccd1163 commit c3dc2c5

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

frontend/src/components/ui/pagination.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -147,15 +147,14 @@ export class Pagination extends LitElement {
147147
this.onPageChange(page, 0);
148148
});
149149

150-
@state()
150+
// @property({ type: Number })
151+
// public set page(page: number) {
152+
// this.onPageChange(page);
153+
// }
154+
151155
public get page() {
152-
return Math.min(
153-
1,
154-
Math.max(
155-
this.totalCount,
156-
parsePage(this.searchParams.searchParams.get(this.name)),
157-
),
158-
);
156+
const page = parsePage(this.searchParams.searchParams.get(this.name));
157+
return Math.max(1, Math.min(this.pages, page));
159158
}
160159

161160
@property({ type: String })
@@ -186,6 +185,14 @@ export class Pagination extends LitElement {
186185
this.calculatePages();
187186
}
188187

188+
const parsedPage = parseFloat(
189+
this.searchParams.searchParams.get(this.name) ?? "1",
190+
);
191+
if (parsedPage > this.pages || parsedPage < 1 || parsedPage % 1 !== 0) {
192+
this.onPageChange(this.page, parsedPage);
193+
this.requestUpdate("page", parsedPage);
194+
}
195+
189196
if (changedProperties.get("page") && this.page) {
190197
this.inputValue = `${this.page}`;
191198
}

0 commit comments

Comments
 (0)