Handle back/forward page in advanced search
This commit is contained in:
parent
0b18f4aa80
commit
7afea880e5
|
@ -32,14 +32,14 @@ export class AdvancedSearch {
|
||||||
}) {
|
}) {
|
||||||
if (!options) return
|
if (!options) return
|
||||||
|
|
||||||
this.startDate = options.startDate
|
this.startDate = options.startDate || undefined
|
||||||
this.endDate = options.endDate
|
this.endDate = options.endDate || undefined
|
||||||
this.nsfw = options.nsfw
|
this.nsfw = options.nsfw || undefined
|
||||||
this.categoryOneOf = options.categoryOneOf
|
this.categoryOneOf = options.categoryOneOf || undefined
|
||||||
this.licenceOneOf = options.licenceOneOf
|
this.licenceOneOf = options.licenceOneOf || undefined
|
||||||
this.languageOneOf = options.languageOneOf
|
this.languageOneOf = options.languageOneOf || undefined
|
||||||
this.tagsOneOf = options.tagsOneOf
|
this.tagsOneOf = options.tagsOneOf || undefined
|
||||||
this.tagsAllOf = options.tagsAllOf
|
this.tagsAllOf = options.tagsAllOf || undefined
|
||||||
this.durationMin = parseInt(options.durationMin, 10)
|
this.durationMin = parseInt(options.durationMin, 10)
|
||||||
this.durationMax = parseInt(options.durationMax, 10)
|
this.durationMax = parseInt(options.durationMax, 10)
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,7 @@ export class SearchComponent implements OnInit, OnDestroy {
|
||||||
|
|
||||||
private subActivatedRoute: Subscription
|
private subActivatedRoute: Subscription
|
||||||
private currentSearch: string
|
private currentSearch: string
|
||||||
|
private isInitialLoad = true
|
||||||
|
|
||||||
constructor (
|
constructor (
|
||||||
private i18n: I18n,
|
private i18n: I18n,
|
||||||
|
@ -39,23 +40,28 @@ export class SearchComponent implements OnInit, OnDestroy {
|
||||||
) { }
|
) { }
|
||||||
|
|
||||||
ngOnInit () {
|
ngOnInit () {
|
||||||
this.advancedSearch = new AdvancedSearch(this.route.snapshot.queryParams)
|
|
||||||
if (this.advancedSearch.containsValues()) this.isSearchFilterCollapsed = false
|
|
||||||
|
|
||||||
this.subActivatedRoute = this.route.queryParams.subscribe(
|
this.subActivatedRoute = this.route.queryParams.subscribe(
|
||||||
queryParams => {
|
queryParams => {
|
||||||
const querySearch = queryParams['search']
|
const querySearch = queryParams['search']
|
||||||
|
|
||||||
if (!querySearch) return this.redirectService.redirectToHomepage()
|
if (!querySearch) return this.redirectService.redirectToHomepage()
|
||||||
if (querySearch === this.currentSearch) return
|
|
||||||
|
|
||||||
// Search updated, reset filters
|
// Search updated, reset filters
|
||||||
if (this.currentSearch) this.advancedSearch.reset()
|
if (this.currentSearch !== querySearch) {
|
||||||
|
this.resetPagination()
|
||||||
|
this.advancedSearch.reset()
|
||||||
|
|
||||||
this.currentSearch = querySearch
|
this.currentSearch = querySearch
|
||||||
this.updateTitle()
|
this.updateTitle()
|
||||||
|
}
|
||||||
|
|
||||||
this.reload()
|
this.advancedSearch = new AdvancedSearch(queryParams)
|
||||||
|
|
||||||
|
// Don't hide filters if we have some of them AND the user just came on the webpage
|
||||||
|
this.isSearchFilterCollapsed = this.isInitialLoad === false || !this.advancedSearch.containsValues()
|
||||||
|
this.isInitialLoad = false
|
||||||
|
|
||||||
|
this.search()
|
||||||
},
|
},
|
||||||
|
|
||||||
err => this.notificationsService.error('Error', err.text)
|
err => this.notificationsService.error('Error', err.text)
|
||||||
|
@ -89,20 +95,16 @@ export class SearchComponent implements OnInit, OnDestroy {
|
||||||
}
|
}
|
||||||
|
|
||||||
onFiltered () {
|
onFiltered () {
|
||||||
this.updateUrlFromAdvancedSearch()
|
this.resetPagination()
|
||||||
// Hide the filters
|
|
||||||
this.isSearchFilterCollapsed = true
|
|
||||||
|
|
||||||
this.reload()
|
this.updateUrlFromAdvancedSearch()
|
||||||
}
|
}
|
||||||
|
|
||||||
private reload () {
|
private resetPagination () {
|
||||||
this.pagination.currentPage = 1
|
this.pagination.currentPage = 1
|
||||||
this.pagination.totalItems = null
|
this.pagination.totalItems = null
|
||||||
|
|
||||||
this.videos = []
|
this.videos = []
|
||||||
|
|
||||||
this.search()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private updateTitle () {
|
private updateTitle () {
|
||||||
|
|
|
@ -44,7 +44,7 @@ export class SearchService {
|
||||||
const value = advancedSearchObject[name]
|
const value = advancedSearchObject[name]
|
||||||
if (!value) continue
|
if (!value) continue
|
||||||
|
|
||||||
if (Array.isArray(value)) {
|
if (Array.isArray(value) && value.length !== 0) {
|
||||||
for (const v of value) params = params.append(name, v)
|
for (const v of value) params = params.append(name, v)
|
||||||
} else {
|
} else {
|
||||||
params = params.append(name, value)
|
params = params.append(name, value)
|
||||||
|
|
Loading…
Reference in New Issue