Skip to content

Commit

Permalink
refactor: Move queries into loops
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitrylyzo committed Oct 5, 2023
1 parent 38fcd31 commit 37c69e3
Showing 1 changed file with 13 additions and 23 deletions.
36 changes: 13 additions & 23 deletions src/components/filtermenu/filtermenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}
}

Expand All @@ -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'));
}
}

Expand Down

0 comments on commit 37c69e3

Please sign in to comment.