aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/header/header.component.ts
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/header/header.component.ts')
-rw-r--r--client/src/app/header/header.component.ts41
1 files changed, 0 insertions, 41 deletions
diff --git a/client/src/app/header/header.component.ts b/client/src/app/header/header.component.ts
index ca4a32cbc..d9311c554 100644
--- a/client/src/app/header/header.component.ts
+++ b/client/src/app/header/header.component.ts
@@ -1,9 +1,4 @@
1import { filter, first, map, tap } from 'rxjs/operators'
2import { Component, OnInit } from '@angular/core' 1import { Component, OnInit } from '@angular/core'
3import { ActivatedRoute, NavigationEnd, Params, Router } from '@angular/router'
4import { getParameterByName } from '../shared/misc/utils'
5import { AuthService } from '@app/core'
6import { of } from 'rxjs'
7import { I18n } from '@ngx-translate/i18n-polyfill' 2import { I18n } from '@ngx-translate/i18n-polyfill'
8 3
9@Component({ 4@Component({
@@ -17,46 +12,10 @@ export class HeaderComponent implements OnInit {
17 ariaLabelTextForSearch = '' 12 ariaLabelTextForSearch = ''
18 13
19 constructor ( 14 constructor (
20 private router: Router,
21 private route: ActivatedRoute,
22 private auth: AuthService,
23 private i18n: I18n 15 private i18n: I18n
24 ) {} 16 ) {}
25 17
26 ngOnInit () { 18 ngOnInit () {
27 this.ariaLabelTextForSearch = this.i18n('Search videos, channels') 19 this.ariaLabelTextForSearch = this.i18n('Search videos, channels')
28
29 this.router.events
30 .pipe(
31 filter(e => e instanceof NavigationEnd),
32 map(() => getParameterByName('search', window.location.href))
33 )
34 .subscribe(searchQuery => this.searchValue = searchQuery || '')
35 }
36
37 doSearch () {
38 const queryParams: Params = {}
39
40 if (window.location.pathname === '/search' && this.route.snapshot.queryParams) {
41 Object.assign(queryParams, this.route.snapshot.queryParams)
42 }
43
44 Object.assign(queryParams, { search: this.searchValue })
45
46 const o = this.auth.isLoggedIn()
47 ? this.loadUserLanguagesIfNeeded(queryParams)
48 : of(true)
49
50 o.subscribe(() => this.router.navigate([ '/search' ], { queryParams }))
51 }
52
53 private loadUserLanguagesIfNeeded (queryParams: any) {
54 if (queryParams && queryParams.languageOneOf) return of(queryParams)
55
56 return this.auth.userInformationLoaded
57 .pipe(
58 first(),
59 tap(() => Object.assign(queryParams, { languageOneOf: this.auth.getUser().videoLanguages }))
60 )
61 } 20 }
62} 21}