From 55269c0460207ebd924fedeeb88fc0bca973b96d Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 10 Jun 2022 09:40:20 +0200 Subject: Fix search filters count --- .../shared/shared-search/advanced-search.model.ts | 31 ++++++++++------------ 1 file changed, 14 insertions(+), 17 deletions(-) (limited to 'client/src/app/shared/shared-search') diff --git a/client/src/app/shared/shared-search/advanced-search.model.ts b/client/src/app/shared/shared-search/advanced-search.model.ts index e40fd2e66..1375820da 100644 --- a/client/src/app/shared/shared-search/advanced-search.model.ts +++ b/client/src/app/shared/shared-search/advanced-search.model.ts @@ -40,9 +40,6 @@ export class AdvancedSearch { searchTarget: SearchTargetType resultType: AdvancedSearchResultType - // Filters we don't want to count, because they are mandatory - private silentFilters = new Set([ 'sort', 'searchTarget' ]) - constructor (options?: { startDate?: string endDate?: string @@ -101,14 +98,7 @@ export class AdvancedSearch { } containsValues () { - const obj = this.toUrlObject() - for (const k of Object.keys(obj)) { - if (this.silentFilters.has(k)) continue - - if (this.isValidValue(obj[k])) return true - } - - return false + return this.size() !== 0 } reset () { @@ -193,12 +183,19 @@ export class AdvancedSearch { size () { let acc = 0 - const obj = this.toUrlObject() - for (const k of Object.keys(obj)) { - if (this.silentFilters.has(k)) continue - - if (this.isValidValue(obj[k])) acc++ - } + if (this.isValidValue(this.startDate) || this.isValidValue(this.endDate)) acc++ + if (this.isValidValue(this.originallyPublishedStartDate) || this.isValidValue(this.originallyPublishedEndDate)) acc++ + + if (this.isValidValue(this.nsfw)) acc++ + if (this.isValidValue(this.categoryOneOf)) acc++ + if (this.isValidValue(this.licenceOneOf)) acc++ + if (this.isValidValue(this.languageOneOf)) acc++ + if (this.isValidValue(this.tagsOneOf)) acc++ + if (this.isValidValue(this.tagsAllOf)) acc++ + if (this.isValidValue(this.durationMin) || this.isValidValue(this.durationMax)) acc++ + if (this.isValidValue(this.isLive)) acc++ + if (this.isValidValue(this.host)) acc++ + if (this.isValidValue(this.resultType)) acc++ return acc } -- cgit v1.2.3