ui: remember scoreboard filter when navigating

This commit is contained in:
undefined committed 2025-11-09 20:01:29 +08:00
1 parent 2fd4b02d6d
commit 9898c56de1
2 files changed
+24 -2

No files matched your search

@@ -45,7 +45,7 @@ export default new AutoloadPage('customFont', (pageName) => {
}
dialog.open().then((action) => {
console.log(action, saveKey, selection);
if (action === 'ok') {
if (action === 'ok' && selection) {
localStorage.setItem(saveKey, selection);
window.location.reload();
} else {
@@ -44,7 +44,22 @@ const page = new NamedPage(['contest_scoreboard', 'homework_scoreboard'], async
uids.forEach((uid) => $(`.user--${uid}`).closest('tr').show());
}
}
$('.select.filter').on('change', update);
function getFilterFromHash() {
const hash = location.hash.slice(1);
if (hash.startsWith('filter=')) return hash.slice(7);
return null;
}
const initialFilter = getFilterFromHash() || 'all';
$('.select.filter').val(initialFilter);
await update();
$('.select.filter').on('change', async () => {
await update();
const val = $('.select.filter').val();
history.replaceState(null, '', `#filter=${val}`);
});
const beginAt = new Date(UiContext.tdoc.beginAt).getTime();
const endAt = new Date(UiContext.tdoc.endAt).getTime();
@@ -57,6 +72,13 @@ const page = new NamedPage(['contest_scoreboard', 'homework_scoreboard'], async
}
setInterval(updateScoreboard, 180000);
window.addEventListener('hashchange', async () => {
const filter = getFilterFromHash();
if (filter) {
$('.select.filter').val(filter);
await update();
}
});
});
export default page;