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 --- client/src/app/+search/search-filters.component.ts | 8 +++--- .../shared/shared-search/advanced-search.model.ts | 31 ++++++++++------------ 2 files changed, 18 insertions(+), 21 deletions(-) (limited to 'client/src/app') diff --git a/client/src/app/+search/search-filters.component.ts b/client/src/app/+search/search-filters.component.ts index aaa4ecc5a..f9de04706 100644 --- a/client/src/app/+search/search-filters.component.ts +++ b/client/src/app/+search/search-filters.component.ts @@ -138,11 +138,11 @@ export class SearchFiltersComponent implements OnInit { private loadOriginallyPublishedAtYears () { this.originallyPublishedStartYear = this.advancedSearch.originallyPublishedStartDate ? new Date(this.advancedSearch.originallyPublishedStartDate).getFullYear().toString() - : null + : undefined this.originallyPublishedEndYear = this.advancedSearch.originallyPublishedEndDate ? new Date(this.advancedSearch.originallyPublishedEndDate).getFullYear().toString() - : null + : undefined } private loadFromDurationRange () { @@ -189,7 +189,7 @@ export class SearchFiltersComponent implements OnInit { this.advancedSearch.originallyPublishedStartDate = start.toISOString() } else { - this.advancedSearch.originallyPublishedStartDate = null + this.advancedSearch.originallyPublishedStartDate = undefined } if (this.originallyPublishedEndYear) { @@ -199,7 +199,7 @@ export class SearchFiltersComponent implements OnInit { this.advancedSearch.originallyPublishedEndDate = end.toISOString() } else { - this.advancedSearch.originallyPublishedEndDate = null + this.advancedSearch.originallyPublishedEndDate = undefined } } 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