From 9398857d93fcf44237c8d73d18ef144e53ccc2d7 Mon Sep 17 00:00:00 2001 From: tophf Date: Tue, 6 Sep 2022 01:07:14 +0300 Subject: [PATCH] clear searchMode along with search --- js/router.js | 11 +++++++++-- manage/filters.js | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/js/router.js b/js/router.js index 76aa4c70..d3fb1de4 100644 --- a/js/router.js +++ b/js/router.js @@ -78,9 +78,16 @@ const router = { router.update(); }, - updateSearch(key, value) { + /** + * @param {Object|string} what - an object or a single key + * @param {string} [value] - for `key` mode + */ + updateSearch(what, value) { const u = new URL(location); - u.searchParams[value ? 'set' : 'delete'](key, value); + const entries = typeof what === 'object' ? Object.entries(what) : [[what, value]]; + for (const [key, val] of entries) { + u.searchParams[val ? 'set' : 'delete'](key, val); + } history.replaceState(history.state, null, `${u}`); router.update(true); }, diff --git a/manage/filters.js b/manage/filters.js index 0484fa04..ca326a38 100644 --- a/manage/filters.js +++ b/manage/filters.js @@ -114,7 +114,7 @@ function initFilters() { } } filterOnChange({forceRefilter: true}); - router.updateSearch('search', ''); + router.updateSearch({search: '', searchMode: ''}); }; filterOnChange({forceRefilter: true});