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(this.startDate) || this.isValidValue(this.endDate)) acc++ + if (this.isValidValue(this.originallyPublishedStartDate) || this.isValidValue(this.originallyPublishedEndDate)) acc++ - if (this.isValidValue(obj[k])) 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 }