From 6341a71fec882726bdffa4ed3460a6cbcf252d6e Mon Sep 17 00:00:00 2001 From: grafixeyehero Date: Fri, 21 Oct 2022 21:47:54 +0300 Subject: [PATCH] use single state and local storage --- src/components/filtermenu/filtermenu.js | 47 +- .../filtermenu/filtermenu.template.html | 26 +- src/components/sortmenu/sortmenu.js | 21 +- src/components/viewSettings/viewSettings.js | 25 +- .../viewSettings/viewSettings.template.html | 8 +- src/controllers/list.js | 10 +- src/view/components/AlphaPickerContainer.tsx | 22 +- src/view/components/Filter.tsx | 25 +- src/view/components/ItemsContainer.tsx | 90 +--- src/view/components/Pagination.tsx | 24 +- src/view/components/SelectView.tsx | 35 +- src/view/components/Sort.tsx | 31 +- src/view/components/ViewItemsContainer.tsx | 487 +++++++++--------- src/view/components/interface.ts | 68 ++- src/view/hook/useLocalStorage.tsx | 20 + 15 files changed, 458 insertions(+), 481 deletions(-) create mode 100644 src/view/hook/useLocalStorage.tsx diff --git a/src/components/filtermenu/filtermenu.js b/src/components/filtermenu/filtermenu.js index 12f535a18d2..d6b85256a98 100644 --- a/src/components/filtermenu/filtermenu.js +++ b/src/components/filtermenu/filtermenu.js @@ -102,15 +102,8 @@ function onInputCommand(e) { break; } } -function saveValues(context, settings, settingsKey) { +function saveValues(context, settings, settingsKey, setfilters) { let 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]); - } else { - setBasicFilter(context, settingsKey + '-filter-' + elems[i].getAttribute('data-settingname'), elems[i].querySelector('input')); - } - } // Video type const videoTypes = []; @@ -121,7 +114,6 @@ function saveValues(context, settings, settingsKey) { videoTypes.push(elems[i].getAttribute('data-filter')); } } - userSettings.setFilter(settingsKey + '-filter-VideoTypes', videoTypes.join(',')); // Series status const seriesStatuses = []; @@ -132,7 +124,6 @@ function saveValues(context, settings, settingsKey) { seriesStatuses.push(elems[i].getAttribute('data-filter')); } } - userSettings.setFilter(`${settingsKey}-filter-SeriesStatus`, seriesStatuses.join(',')); // Genres const genres = []; @@ -143,7 +134,39 @@ function saveValues(context, settings, settingsKey) { genres.push(elems[i].getAttribute('data-filter')); } } - userSettings.setFilter(settingsKey + '-filter-GenreIds', genres.join(',')); + + if (setfilters) { + setfilters((prevState) => ({ + ...prevState, + StartIndex: 0, + IsPlayed: context.querySelector('.chkPlayed').checked, + IsUnplayed: context.querySelector('.chkUnplayed').checked, + IsFavorite: context.querySelector('.chkFavorite').checked, + IsResumable: context.querySelector('.chkResumable').checked, + Is4K: context.querySelector('.chk4KFilter').checked, + IsHD: context.querySelector('.chkHDFilter').checked, + IsSD: context.querySelector('.chkSDFilter').checked, + Is3D: context.querySelector('.chk3DFilter').checked, + VideoTypes: videoTypes.join(','), + SeriesStatus: seriesStatuses.join(','), + HasSubtitles: context.querySelector('.chkSubtitle').checked, + HasTrailer: context.querySelector('.chkTrailer').checked, + HasSpecialFeature: context.querySelector('.chkSpecialFeature').checked, + HasThemeSong: context.querySelector('.chkThemeSong').checked, + HasThemeVideo: context.querySelector('.chkThemeVideo').checked, + GenreIds: genres.join(',') + })); + } else { + 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]); + } else { + setBasicFilter(context, settingsKey + '-filter-' + elems[i].getAttribute('data-settingname'), elems[i].querySelector('input')); + } + } + + userSettings.setFilter(settingsKey + '-filter-GenreIds', genres.join(',')); + } } function bindCheckboxInput(context, on) { const elems = context.querySelectorAll('.checkboxList-verticalwrap'); @@ -275,7 +298,7 @@ class FilterMenu { if (submitted) { //if (!options.onChange) { - saveValues(dlg, options.settings, options.settingsKey); + saveValues(dlg, options.settings, options.settingsKey, options.setfilters); return resolve(); //} } diff --git a/src/components/filtermenu/filtermenu.template.html b/src/components/filtermenu/filtermenu.template.html index 1a5545baa34..cacc69cf43a 100644 --- a/src/components/filtermenu/filtermenu.template.html +++ b/src/components/filtermenu/filtermenu.template.html @@ -5,19 +5,19 @@
@@ -49,22 +49,22 @@

${HeaderVideoType}