aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/search
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/search')
-rw-r--r--client/src/app/search/advanced-search.model.ts16
-rw-r--r--client/src/app/search/search.component.ts32
-rw-r--r--client/src/app/search/search.service.ts2
3 files changed, 26 insertions, 24 deletions
diff --git a/client/src/app/search/advanced-search.model.ts b/client/src/app/search/advanced-search.model.ts
index a0f333175..aad436788 100644
--- a/client/src/app/search/advanced-search.model.ts
+++ b/client/src/app/search/advanced-search.model.ts
@@ -32,14 +32,14 @@ export class AdvancedSearch {
32 }) { 32 }) {
33 if (!options) return 33 if (!options) return
34 34
35 this.startDate = options.startDate 35 this.startDate = options.startDate || undefined
36 this.endDate = options.endDate 36 this.endDate = options.endDate || undefined
37 this.nsfw = options.nsfw 37 this.nsfw = options.nsfw || undefined
38 this.categoryOneOf = options.categoryOneOf 38 this.categoryOneOf = options.categoryOneOf || undefined
39 this.licenceOneOf = options.licenceOneOf 39 this.licenceOneOf = options.licenceOneOf || undefined
40 this.languageOneOf = options.languageOneOf 40 this.languageOneOf = options.languageOneOf || undefined
41 this.tagsOneOf = options.tagsOneOf 41 this.tagsOneOf = options.tagsOneOf || undefined
42 this.tagsAllOf = options.tagsAllOf 42 this.tagsAllOf = options.tagsAllOf || undefined
43 this.durationMin = parseInt(options.durationMin, 10) 43 this.durationMin = parseInt(options.durationMin, 10)
44 this.durationMax = parseInt(options.durationMax, 10) 44 this.durationMax = parseInt(options.durationMax, 10)
45 45
diff --git a/client/src/app/search/search.component.ts b/client/src/app/search/search.component.ts
index 09028fec5..8860b9268 100644
--- a/client/src/app/search/search.component.ts
+++ b/client/src/app/search/search.component.ts
@@ -27,6 +27,7 @@ export class SearchComponent implements OnInit, OnDestroy {
27 27
28 private subActivatedRoute: Subscription 28 private subActivatedRoute: Subscription
29 private currentSearch: string 29 private currentSearch: string
30 private isInitialLoad = true
30 31
31 constructor ( 32 constructor (
32 private i18n: I18n, 33 private i18n: I18n,
@@ -39,23 +40,28 @@ export class SearchComponent implements OnInit, OnDestroy {
39 ) { } 40 ) { }
40 41
41 ngOnInit () { 42 ngOnInit () {
42 this.advancedSearch = new AdvancedSearch(this.route.snapshot.queryParams)
43 if (this.advancedSearch.containsValues()) this.isSearchFilterCollapsed = false
44
45 this.subActivatedRoute = this.route.queryParams.subscribe( 43 this.subActivatedRoute = this.route.queryParams.subscribe(
46 queryParams => { 44 queryParams => {
47 const querySearch = queryParams['search'] 45 const querySearch = queryParams['search']
48 46
49 if (!querySearch) return this.redirectService.redirectToHomepage() 47 if (!querySearch) return this.redirectService.redirectToHomepage()
50 if (querySearch === this.currentSearch) return
51 48
52 // Search updated, reset filters 49 // Search updated, reset filters
53 if (this.currentSearch) this.advancedSearch.reset() 50 if (this.currentSearch !== querySearch) {
51 this.resetPagination()
52 this.advancedSearch.reset()
53
54 this.currentSearch = querySearch
55 this.updateTitle()
56 }
57
58 this.advancedSearch = new AdvancedSearch(queryParams)
54 59
55 this.currentSearch = querySearch 60 // Don't hide filters if we have some of them AND the user just came on the webpage
56 this.updateTitle() 61 this.isSearchFilterCollapsed = this.isInitialLoad === false || !this.advancedSearch.containsValues()
62 this.isInitialLoad = false
57 63
58 this.reload() 64 this.search()
59 }, 65 },
60 66
61 err => this.notificationsService.error('Error', err.text) 67 err => this.notificationsService.error('Error', err.text)
@@ -89,20 +95,16 @@ export class SearchComponent implements OnInit, OnDestroy {
89 } 95 }
90 96
91 onFiltered () { 97 onFiltered () {
92 this.updateUrlFromAdvancedSearch() 98 this.resetPagination()
93 // Hide the filters
94 this.isSearchFilterCollapsed = true
95 99
96 this.reload() 100 this.updateUrlFromAdvancedSearch()
97 } 101 }
98 102
99 private reload () { 103 private resetPagination () {
100 this.pagination.currentPage = 1 104 this.pagination.currentPage = 1
101 this.pagination.totalItems = null 105 this.pagination.totalItems = null
102 106
103 this.videos = [] 107 this.videos = []
104
105 this.search()
106 } 108 }
107 109
108 private updateTitle () { 110 private updateTitle () {
diff --git a/client/src/app/search/search.service.ts b/client/src/app/search/search.service.ts
index c6106afd6..b46cb97f4 100644
--- a/client/src/app/search/search.service.ts
+++ b/client/src/app/search/search.service.ts
@@ -44,7 +44,7 @@ export class SearchService {
44 const value = advancedSearchObject[name] 44 const value = advancedSearchObject[name]
45 if (!value) continue 45 if (!value) continue
46 46
47 if (Array.isArray(value)) { 47 if (Array.isArray(value) && value.length !== 0) {
48 for (const v of value) params = params.append(name, v) 48 for (const v of value) params = params.append(name, v)
49 } else { 49 } else {
50 params = params.append(name, value) 50 params = params.append(name, value)