From ddf003c4c5981dc7bcc129cc9b9ea216e95ae892 Mon Sep 17 00:00:00 2001 From: undefined Date: Sat, 6 Dec 2025 22:37:01 +0800 Subject: [PATCH] ui: re-impl #1094 --- packages/ui-default/backendlib/misc.ts | 5 +++++ packages/ui-default/backendlib/template.ts | 2 +- packages/ui-default/templates/partials/problem_list.html | 4 ++-- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/ui-default/backendlib/misc.ts b/packages/ui-default/backendlib/misc.ts index 0c0ff9e8f..2a8dbc778 100644 --- a/packages/ui-default/backendlib/misc.ts +++ b/packages/ui-default/backendlib/misc.ts @@ -47,3 +47,8 @@ export function* paginate(page: number, numPages: number) { if (page < numPages - 1) yield ['last', numPages]; } } + +export function buildQueryString(obj: Record) { + return Object.entries(obj).filter(([key, value]) => value && !key.startsWith('__')) + .map(([key, value]) => `${key}=${encodeURIComponent(value)}`).join('&'); +} diff --git a/packages/ui-default/backendlib/template.ts b/packages/ui-default/backendlib/template.ts index 0a15a09ff..4a8ddcdf6 100644 --- a/packages/ui-default/backendlib/template.ts +++ b/packages/ui-default/backendlib/template.ts @@ -130,7 +130,7 @@ class Nunjucks extends nunjucks.Environment { this.addGlobal('instanceof', (a, b) => a instanceof b); this.addGlobal('paginate', misc.paginate); this.addGlobal('size', misc.size); - this.addGlobal('utils', { status, getAlphabeticId }); + this.addGlobal('utils', { status, getAlphabeticId, buildQueryString: misc.buildQueryString }); this.addGlobal('avatarUrl', avatar); this.addGlobal('formatSeconds', misc.formatSeconds); this.addGlobal('model', global.Hydro.model); diff --git a/packages/ui-default/templates/partials/problem_list.html b/packages/ui-default/templates/partials/problem_list.html index 259cc4df9..ca4912907 100644 --- a/packages/ui-default/templates/partials/problem_list.html +++ b/packages/ui-default/templates/partials/problem_list.html @@ -6,7 +6,7 @@ {% if not pdocs.length %} {{ nothing.render('Sorry, there are no problems in the problem set.') }} {% else %} - {{ paginator.render(page, ppcount, position='top', add_qs=('q=' + qs if qs else '')) }} + {{ paginator.render(page, ppcount, position='top', add_qs=utils.buildQueryString(q=qs, sort='' if sort == 'default' else sort)) }} @@ -63,6 +63,6 @@ {%- endfor -%}
- {{ paginator.render(page, ppcount, add_qs=('q=' + qs if qs else '')) }} + {{ paginator.render(page, ppcount, add_qs=utils.buildQueryString(q=qs, sort='' if sort == 'default' else sort)) }} {% endif %}