Skip to content

Commit 9d0a378

Browse files
authored
Merge pull request #6264 from WoltLab/6.2-search-pagination
Replace deprecated `UiPagination` in search results
2 parents be1cdae + 84796be commit 9d0a378

File tree

2 files changed

+65
-27
lines changed

2 files changed

+65
-27
lines changed

ts/WoltLabSuite/Core/Ui/Search/Extended.ts

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import { dboAction } from "../../Ajax";
1111
import DatePicker from "../../Date/Picker";
1212
import * as DomUtil from "../../Dom/Util";
1313
import { ucfirst } from "../../StringUtil";
14-
import UiPagination from "../Pagination";
1514
import UiSearchInput from "./Input";
1615
import * as UiScroll from "../Scroll";
1716
import { setValues as setItemListValues } from "../ItemList";
@@ -242,21 +241,43 @@ export class UiSearchExtended {
242241
const wrapperDiv = document.createElement("div");
243242
wrapperDiv.classList.add("pagination" + ucfirst(position));
244243
this.form.parentElement!.insertBefore(wrapperDiv, this.delimiter);
245-
const div = document.createElement("div");
246-
wrapperDiv.appendChild(div);
247244

248-
new UiPagination(div, {
249-
activePage: this.activePage,
250-
maxPage: this.pages,
245+
const pagination = document.createElement("woltlab-core-pagination");
246+
pagination.page = this.activePage;
247+
pagination.count = this.pages;
248+
pagination.behavior = "button";
249+
pagination.url = this.getPaginationUrl();
250+
pagination.addEventListener("switchPage", (event: CustomEvent) => {
251+
void this.changePage(event.detail).then(() => {
252+
if (position === "bottom") {
253+
UiScroll.element(this.form.nextElementSibling as HTMLElement, undefined, "auto");
254+
}
255+
});
256+
});
251257

252-
callbackSwitch: (pageNo) => {
253-
void this.changePage(pageNo).then(() => {
254-
if (position === "bottom") {
255-
UiScroll.element(this.form.nextElementSibling as HTMLElement, undefined, "auto");
256-
}
257-
});
258-
},
258+
wrapperDiv.append(pagination);
259+
}
260+
261+
private getPaginationUrl(): string {
262+
const url = new URL(this.form.action);
263+
url.search += url.search !== "" ? "&" : "?";
264+
265+
const searchParameters: SearchParameters = [];
266+
new FormData(this.form).forEach((value, key) => {
267+
// eslint-disable-next-line @typescript-eslint/no-base-to-string
268+
const trimmed = value.toString().trim();
269+
if (trimmed) {
270+
searchParameters.push([key, trimmed]);
271+
}
259272
});
273+
const parameters = searchParameters.slice();
274+
275+
if (this.activePage > 1) {
276+
parameters.push(["pageNo", this.activePage.toString()]);
277+
}
278+
url.search += new URLSearchParams(parameters).toString();
279+
280+
return url.toString();
260281
}
261282

262283
private async changePage(pageNo: number): Promise<void> {

wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Search/Extended.js

Lines changed: 31 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)