Skip to content

Commit

Permalink
Move allowedFilterSettings to constants file
Browse files Browse the repository at this point in the history
  • Loading branch information
engine committed Nov 26, 2024
1 parent e78fbef commit 2bd2496
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 52 deletions.
26 changes: 4 additions & 22 deletions src/components/filterdialog/filterIndicator.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,10 @@
import './filterIndicator.scss';
import { ALLOWED_FILTER_SETTINGS } from '../../constants/allowedFilterSettings';

export function getFilterStatus(query) {
return Boolean(
query.Filters
|| query.IsFavorite
|| query.VideoTypes
|| query.SeriesStatus
|| query.Is4K
|| (query.IsHD !== undefined && query.IsHD !== null)
|| query.IsSD
|| query.Is3D
|| query.HasSubtitles
|| query.HasTrailer
|| query.HasSpecialFeature
|| query.HasThemeSong
|| query.HasThemeVideo
|| query.IsMissing
|| query.ParentIndexNumber
|| query.Genres
|| query.Tags
|| query.Years
|| query.OfficialRatings
|| query.IsUnaired
);
return ALLOWED_FILTER_SETTINGS.some(setting => {
return query[setting] !== undefined && query[setting] !== null;
});
}

export function setFilterStatus(page, query) {
Expand Down
25 changes: 4 additions & 21 deletions src/components/filterdialog/filterdialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import './style.scss';
import ServerConnections from '../ServerConnections';
import template from './filterdialog.template.html';
import { stopMultiSelect } from '../../components/multiSelect/multiSelect';
import { ALLOWED_FILTER_SETTINGS } from '../../constants/allowedFilterSettings';

function merge(resultItems, queryItems, delimiter) {
if (!queryItems) {
Expand Down Expand Up @@ -248,27 +249,9 @@ class FilterDialog {
*/
onResetAllFilters(context) {
const query = this.options.query;
query.Filters = null;
query.IsFavorite = null;
query.VideoTypes = null;
query.SeriesStatus = null;
query.Is4K = null;
query.IsHD = null;
query.IsSD = null;
query.Is3D = null;
query.HasSubtitles = null;
query.HasTrailer = null;
query.HasSpecialFeature = null;
query.HasThemeSong = null;
query.HasThemeVideo = null;
query.IsMissing = null;
query.ParentIndexNumber = null;
query.Genres = null;
query.Tags = null;
query.Years = null;
query.OfficialRatings = null;
query.IsUnaired = null;
query.SeriesStatus = null;
ALLOWED_FILTER_SETTINGS.forEach(setting => {
query[setting] = null;
});
query.StartIndex = 0;
for (const elem of context.querySelectorAll('input[type=checkbox]')) {
elem.checked = false;
Expand Down
8 changes: 8 additions & 0 deletions src/constants/allowedFilterSettings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/** The allowed filter settings */
export const ALLOWED_FILTER_SETTINGS = [
'Filters', 'HasSubtitles', 'HasTrailer', 'HasSpecialFeature',
'HasThemeSong', 'HasThemeVideo', 'Genres', 'OfficialRatings',
'Tags', 'VideoTypes', 'IsSD', 'IsHD', 'Is4K', 'Is3D',
'IsFavorite', 'IsMissing', 'IsUnaired', 'ParentIndexNumber',
'SeriesStatus', 'Years'
];
12 changes: 3 additions & 9 deletions src/scripts/settings/userSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Events from '../../utils/events.ts';
import { toBoolean } from '../../utils/string.ts';
import browser from '../browser';
import appSettings from './appSettings';
import { ALLOWED_FILTER_SETTINGS } from '../../constants/allowedFilterSettings';

function onSaveTimeout() {
const self = this;
Expand All @@ -20,13 +21,6 @@ function saveServerPreferences(instance) {
const allowedSortSettings = ['SortBy', 'SortOrder'];

const filterSettingsPostfix = '-filter';
const allowedFilterSettings = [
'Filters', 'HasSubtitles', 'HasTrailer', 'HasSpecialFeature',
'HasThemeSong', 'HasThemeVideo', 'Genres', 'OfficialRatings',
'Tags', 'VideoTypes', 'IsSD', 'IsHD', 'Is4K', 'Is3D',
'IsFavorite', 'IsMissing', 'IsUnaired', 'ParentIndexNumber',
'SeriesStatus', 'Years'
];

function filterQuerySettings(query, allowedItems) {
return Object.keys(query)
Expand Down Expand Up @@ -548,7 +542,7 @@ export class UserSettings {
sortSettings = filterQuerySettings(JSON.parse(sortSettings), allowedSortSettings);
}
if (filterSettings) {
filterSettings = filterQuerySettings(JSON.parse(filterSettings), allowedFilterSettings);
filterSettings = filterQuerySettings(JSON.parse(filterSettings), ALLOWED_FILTER_SETTINGS);
}

return Object.assign(query, sortSettings, filterSettings);
Expand All @@ -561,7 +555,7 @@ export class UserSettings {
*/
saveQuerySettings(key, query) {
const sortSettings = filterQuerySettings(query, allowedSortSettings);
const filterSettings = filterQuerySettings(query, allowedFilterSettings);
const filterSettings = filterQuerySettings(query, ALLOWED_FILTER_SETTINGS);

this.set(key, JSON.stringify(sortSettings));
this.set(key + filterSettingsPostfix, JSON.stringify(filterSettings), false);
Expand Down

0 comments on commit 2bd2496

Please sign in to comment.