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/search.component.ts97
1 files changed, 50 insertions, 47 deletions
diff --git a/client/src/app/+search/search.component.ts b/client/src/app/+search/search.component.ts
index 7425b7016..81d1006f8 100644
--- a/client/src/app/+search/search.component.ts
+++ b/client/src/app/+search/search.component.ts
@@ -73,36 +73,37 @@ export class SearchComponent implements OnInit, OnDestroy {
73 ngOnInit () { 73 ngOnInit () {
74 this.serverConfig = this.serverService.getHTMLConfig() 74 this.serverConfig = this.serverService.getHTMLConfig()
75 75
76 this.subActivatedRoute = this.route.queryParams.subscribe( 76 this.subActivatedRoute = this.route.queryParams
77 async queryParams => { 77 .subscribe({
78 const querySearch = queryParams['search'] 78 next: async queryParams => {
79 const searchTarget = queryParams['searchTarget'] 79 const querySearch = queryParams['search']
80 80 const searchTarget = queryParams['searchTarget']
81 // Search updated, reset filters
82 if (this.currentSearch !== querySearch || searchTarget !== this.advancedSearch.searchTarget) {
83 this.resetPagination()
84 this.advancedSearch.reset()
85
86 this.currentSearch = querySearch || undefined
87 this.updateTitle()
88 }
89 81
90 this.advancedSearch = new AdvancedSearch(queryParams) 82 // Search updated, reset filters
91 if (!this.advancedSearch.searchTarget) { 83 if (this.currentSearch !== querySearch || searchTarget !== this.advancedSearch.searchTarget) {
92 this.advancedSearch.searchTarget = this.getDefaultSearchTarget() 84 this.resetPagination()
93 } 85 this.advancedSearch.reset()
94 86
95 this.error = this.checkFieldsAndGetError() 87 this.currentSearch = querySearch || undefined
88 this.updateTitle()
89 }
96 90
97 // Don't hide filters if we have some of them AND the user just came on the webpage, or we have an error 91 this.advancedSearch = new AdvancedSearch(queryParams)
98 this.isSearchFilterCollapsed = !this.error && (this.isInitialLoad === false || !this.advancedSearch.containsValues()) 92 if (!this.advancedSearch.searchTarget) {
99 this.isInitialLoad = false 93 this.advancedSearch.searchTarget = this.getDefaultSearchTarget()
94 }
100 95
101 this.search() 96 this.error = this.checkFieldsAndGetError()
102 },
103 97
104 err => this.notifier.error(err.text) 98 // Don't hide filters if we have some of them AND the user just came on the webpage, or we have an error
105 ) 99 this.isSearchFilterCollapsed = !this.error && (this.isInitialLoad === false || !this.advancedSearch.containsValues())
100 this.isInitialLoad = false
101
102 this.search()
103 },
104
105 error: err => this.notifier.error(err.text)
106 })
106 107
107 this.userService.getAnonymousOrLoggedUser() 108 this.userService.getAnonymousOrLoggedUser()
108 .subscribe(user => this.userMiniature = user) 109 .subscribe(user => this.userMiniature = user)
@@ -140,33 +141,35 @@ export class SearchComponent implements OnInit, OnDestroy {
140 this.getVideoChannelObs(), 141 this.getVideoChannelObs(),
141 this.getVideoPlaylistObs(), 142 this.getVideoPlaylistObs(),
142 this.getVideosObs() 143 this.getVideosObs()
143 ]).subscribe(results => { 144 ]).subscribe({
144 for (const result of results) { 145 next: results => {
145 this.results = this.results.concat(result.data) 146 for (const result of results) {
146 } 147 this.results = this.results.concat(result.data)
148 }
147 149
148 this.pagination.totalItems = results.reduce((p, r) => p += r.total, 0) 150 this.pagination.totalItems = results.reduce((p, r) => p += r.total, 0)
149 this.lastSearchTarget = this.advancedSearch.searchTarget 151 this.lastSearchTarget = this.advancedSearch.searchTarget
150 152
151 this.hasMoreResults = this.results.length < this.pagination.totalItems 153 this.hasMoreResults = this.results.length < this.pagination.totalItems
152 }, 154 },
153 155
154 err => { 156 error: err => {
155 if (this.advancedSearch.searchTarget !== 'search-index') { 157 if (this.advancedSearch.searchTarget !== 'search-index') {
156 this.notifier.error(err.message) 158 this.notifier.error(err.message)
157 return 159 return
158 } 160 }
159 161
160 this.notifier.error( 162 this.notifier.error(
161 $localize`Search index is unavailable. Retrying with instance results instead.`, 163 $localize`Search index is unavailable. Retrying with instance results instead.`,
162 $localize`Search error` 164 $localize`Search error`
163 ) 165 )
164 this.advancedSearch.searchTarget = 'local' 166 this.advancedSearch.searchTarget = 'local'
165 this.search() 167 this.search()
166 }, 168 },
167 169
168 () => { 170 complete: () => {
169 this.isSearching = false 171 this.isSearching = false
172 }
170 }) 173 })
171 } 174 }
172 175