Fix search filters count

pull/5067/head
Chocobozzz 2022-06-10 09:40:20 +02:00
parent 462a833e4c
commit 55269c0460
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
2 changed files with 17 additions and 20 deletions

View File

@ -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
}
}

View File

@ -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
}