diff options
Diffstat (limited to 'client/src/app/+search/search.component.ts')
-rw-r--r-- | client/src/app/+search/search.component.ts | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/client/src/app/+search/search.component.ts b/client/src/app/+search/search.component.ts index 235bbfa4c..250062e0c 100644 --- a/client/src/app/+search/search.component.ts +++ b/client/src/app/+search/search.component.ts | |||
@@ -4,6 +4,7 @@ import { Component, OnDestroy, OnInit } from '@angular/core' | |||
4 | import { ActivatedRoute, Router } from '@angular/router' | 4 | import { ActivatedRoute, Router } from '@angular/router' |
5 | import { AuthService, HooksService, MetaService, Notifier, ServerService, User, UserService } from '@app/core' | 5 | import { AuthService, HooksService, MetaService, Notifier, ServerService, User, UserService } from '@app/core' |
6 | import { immutableAssign } from '@app/helpers' | 6 | import { immutableAssign } from '@app/helpers' |
7 | import { validateHost } from '@app/shared/form-validators/host-validators' | ||
7 | import { Video, VideoChannel } from '@app/shared/shared-main' | 8 | import { Video, VideoChannel } from '@app/shared/shared-main' |
8 | import { AdvancedSearch, SearchService } from '@app/shared/shared-search' | 9 | import { AdvancedSearch, SearchService } from '@app/shared/shared-search' |
9 | import { MiniatureDisplayOptions } from '@app/shared/shared-video-miniature' | 10 | import { MiniatureDisplayOptions } from '@app/shared/shared-video-miniature' |
@@ -16,6 +17,8 @@ import { HTMLServerConfig, SearchTargetType } from '@shared/models' | |||
16 | templateUrl: './search.component.html' | 17 | templateUrl: './search.component.html' |
17 | }) | 18 | }) |
18 | export class SearchComponent implements OnInit, OnDestroy { | 19 | export class SearchComponent implements OnInit, OnDestroy { |
20 | error: string | ||
21 | |||
19 | results: (Video | VideoChannel)[] = [] | 22 | results: (Video | VideoChannel)[] = [] |
20 | 23 | ||
21 | pagination = { | 24 | pagination = { |
@@ -89,8 +92,10 @@ export class SearchComponent implements OnInit, OnDestroy { | |||
89 | this.advancedSearch.searchTarget = this.getDefaultSearchTarget() | 92 | this.advancedSearch.searchTarget = this.getDefaultSearchTarget() |
90 | } | 93 | } |
91 | 94 | ||
92 | // Don't hide filters if we have some of them AND the user just came on the webpage | 95 | this.error = this.checkFieldsAndGetError() |
93 | this.isSearchFilterCollapsed = this.isInitialLoad === false || !this.advancedSearch.containsValues() | 96 | |
97 | // Don't hide filters if we have some of them AND the user just came on the webpage, or we have an error | ||
98 | this.isSearchFilterCollapsed = !this.error && (this.isInitialLoad === false || !this.advancedSearch.containsValues()) | ||
94 | this.isInitialLoad = false | 99 | this.isInitialLoad = false |
95 | 100 | ||
96 | this.search() | 101 | this.search() |
@@ -126,6 +131,9 @@ export class SearchComponent implements OnInit, OnDestroy { | |||
126 | } | 131 | } |
127 | 132 | ||
128 | search () { | 133 | search () { |
134 | this.error = this.checkFieldsAndGetError() | ||
135 | if (this.error) return | ||
136 | |||
129 | this.isSearching = true | 137 | this.isSearching = true |
130 | 138 | ||
131 | forkJoin([ | 139 | forkJoin([ |
@@ -280,7 +288,7 @@ export class SearchComponent implements OnInit, OnDestroy { | |||
280 | const params = { | 288 | const params = { |
281 | search: this.currentSearch, | 289 | search: this.currentSearch, |
282 | componentPagination: immutableAssign(this.pagination, { itemsPerPage: this.channelsPerPage }), | 290 | componentPagination: immutableAssign(this.pagination, { itemsPerPage: this.channelsPerPage }), |
283 | searchTarget: this.advancedSearch.searchTarget | 291 | advancedSearch: this.advancedSearch |
284 | } | 292 | } |
285 | 293 | ||
286 | return this.hooks.wrapObsFun( | 294 | return this.hooks.wrapObsFun( |
@@ -298,7 +306,7 @@ export class SearchComponent implements OnInit, OnDestroy { | |||
298 | const params = { | 306 | const params = { |
299 | search: this.currentSearch, | 307 | search: this.currentSearch, |
300 | componentPagination: immutableAssign(this.pagination, { itemsPerPage: this.playlistsPerPage }), | 308 | componentPagination: immutableAssign(this.pagination, { itemsPerPage: this.playlistsPerPage }), |
301 | searchTarget: this.advancedSearch.searchTarget | 309 | advancedSearch: this.advancedSearch |
302 | } | 310 | } |
303 | 311 | ||
304 | return this.hooks.wrapObsFun( | 312 | return this.hooks.wrapObsFun( |
@@ -319,4 +327,12 @@ export class SearchComponent implements OnInit, OnDestroy { | |||
319 | 327 | ||
320 | return 'local' | 328 | return 'local' |
321 | } | 329 | } |
330 | |||
331 | private checkFieldsAndGetError () { | ||
332 | if (this.advancedSearch.host && !validateHost(this.advancedSearch.host)) { | ||
333 | return $localize`PeerTube instance host filter is invalid` | ||
334 | } | ||
335 | |||
336 | return undefined | ||
337 | } | ||
322 | } | 338 | } |