From bab1fd7bb9e126c1b179fad9f49f9b161715fb40 Mon Sep 17 00:00:00 2001 From: Dmitry Lyzo Date: Wed, 4 Oct 2023 19:33:09 +0300 Subject: [PATCH 1/3] Fix FilterMenu not saving simple filters Regression 6341a71fec882726bdffa4ed3460a6cbcf252d6e --- src/components/filtermenu/filtermenu.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/components/filtermenu/filtermenu.js b/src/components/filtermenu/filtermenu.js index d7e9c876507..324dca23164 100644 --- a/src/components/filtermenu/filtermenu.js +++ b/src/components/filtermenu/filtermenu.js @@ -103,7 +103,7 @@ function onInputCommand(e) { } } function saveValues(context, settings, settingsKey, setfilters) { - let elems = context.querySelectorAll('.simpleFilter'); + let elems; // Video type const videoTypes = []; @@ -157,6 +157,8 @@ function saveValues(context, settings, settingsKey, setfilters) { GenreIds: genres.join(',') })); } else { + elems = context.querySelectorAll('.simpleFilter'); + for (let i = 0, length = elems.length; i < length; i++) { if (elems[i].tagName === 'INPUT') { setBasicFilter(context, settingsKey + '-filter-' + elems[i].getAttribute('data-settingname'), elems[i]); From b81342d23b11f28871a46a2752d53f8dde02ac77 Mon Sep 17 00:00:00 2001 From: Dmitry Lyzo Date: Wed, 4 Oct 2023 00:09:31 +0300 Subject: [PATCH 2/3] refactor: Move queries into loops --- src/components/filtermenu/filtermenu.js | 36 +++++++++---------------- 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/src/components/filtermenu/filtermenu.js b/src/components/filtermenu/filtermenu.js index 324dca23164..aa6bd5abe33 100644 --- a/src/components/filtermenu/filtermenu.js +++ b/src/components/filtermenu/filtermenu.js @@ -103,35 +103,27 @@ function onInputCommand(e) { } } function saveValues(context, settings, settingsKey, setfilters) { - let elems; - // Video type const videoTypes = []; - elems = context.querySelectorAll('.chkVideoTypeFilter'); - - for (let i = 0, length = elems.length; i < length; i++) { - if (elems[i].checked) { - videoTypes.push(elems[i].getAttribute('data-filter')); + for (const elem of context.querySelectorAll('.chkVideoTypeFilter')) { + if (elem.checked) { + videoTypes.push(elem.getAttribute('data-filter')); } } // Series status const seriesStatuses = []; - elems = context.querySelectorAll('.chkSeriesStatus'); - - for (let i = 0, length = elems.length; i < length; i++) { - if (elems[i].checked) { - seriesStatuses.push(elems[i].getAttribute('data-filter')); + for (const elem of context.querySelectorAll('.chkSeriesStatus')) { + if (elem.checked) { + seriesStatuses.push(elem.getAttribute('data-filter')); } } // Genres const genres = []; - elems = context.querySelectorAll('.chkGenreFilter'); - - for (let i = 0, length = elems.length; i < length; i++) { - if (elems[i].checked) { - genres.push(elems[i].getAttribute('data-filter')); + for (const elem of context.querySelectorAll('.chkGenreFilter')) { + if (elem.checked) { + genres.push(elem.getAttribute('data-filter')); } } @@ -157,13 +149,11 @@ function saveValues(context, settings, settingsKey, setfilters) { GenreIds: genres.join(',') })); } else { - elems = context.querySelectorAll('.simpleFilter'); - - for (let i = 0, length = elems.length; i < length; i++) { - if (elems[i].tagName === 'INPUT') { - setBasicFilter(context, settingsKey + '-filter-' + elems[i].getAttribute('data-settingname'), elems[i]); + for (const elem of context.querySelectorAll('.simpleFilter')) { + if (elem.tagName === 'INPUT') { + setBasicFilter(context, settingsKey + '-filter-' + elem.getAttribute('data-settingname'), elem); } else { - setBasicFilter(context, settingsKey + '-filter-' + elems[i].getAttribute('data-settingname'), elems[i].querySelector('input')); + setBasicFilter(context, settingsKey + '-filter-' + elem.getAttribute('data-settingname'), elem.querySelector('input')); } } From fc37f82e525b85fcbee922fef970388fcaf4dc1a Mon Sep 17 00:00:00 2001 From: Dmitry Lyzo Date: Tue, 10 Oct 2023 09:40:55 +0300 Subject: [PATCH 3/3] refactor: Use forEach for portability --- src/components/filtermenu/filtermenu.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/components/filtermenu/filtermenu.js b/src/components/filtermenu/filtermenu.js index aa6bd5abe33..5c78a6f4a43 100644 --- a/src/components/filtermenu/filtermenu.js +++ b/src/components/filtermenu/filtermenu.js @@ -105,27 +105,27 @@ function onInputCommand(e) { function saveValues(context, settings, settingsKey, setfilters) { // Video type const videoTypes = []; - for (const elem of context.querySelectorAll('.chkVideoTypeFilter')) { + context.querySelectorAll('.chkVideoTypeFilter').forEach(elem => { if (elem.checked) { videoTypes.push(elem.getAttribute('data-filter')); } - } + }); // Series status const seriesStatuses = []; - for (const elem of context.querySelectorAll('.chkSeriesStatus')) { + context.querySelectorAll('.chkSeriesStatus').forEach(elem => { if (elem.checked) { seriesStatuses.push(elem.getAttribute('data-filter')); } - } + }); // Genres const genres = []; - for (const elem of context.querySelectorAll('.chkGenreFilter')) { + context.querySelectorAll('.chkGenreFilter').forEach(elem => { if (elem.checked) { genres.push(elem.getAttribute('data-filter')); } - } + }); if (setfilters) { setfilters((prevState) => ({ @@ -149,13 +149,13 @@ function saveValues(context, settings, settingsKey, setfilters) { GenreIds: genres.join(',') })); } else { - for (const elem of context.querySelectorAll('.simpleFilter')) { + context.querySelectorAll('.simpleFilter').forEach(elem => { if (elem.tagName === 'INPUT') { setBasicFilter(context, settingsKey + '-filter-' + elem.getAttribute('data-settingname'), elem); } else { setBasicFilter(context, settingsKey + '-filter-' + elem.getAttribute('data-settingname'), elem.querySelector('input')); } - } + }); userSettings.setFilter(settingsKey + '-filter-GenreIds', genres.join(',')); }