]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame_incremental - client/src/app/header/header.component.ts
Update translations and support Greek language
[github/Chocobozzz/PeerTube.git] / client / src / app / header / header.component.ts
... / ...
CommitLineData
1import { filter, first, map, tap } from 'rxjs/operators'
2import { Component, OnInit } from '@angular/core'
3import { NavigationEnd, Router } from '@angular/router'
4import { getParameterByName } from '../shared/misc/utils'
5import { AuthService } from '@app/core'
6import { of } from 'rxjs'
7
8@Component({
9 selector: 'my-header',
10 templateUrl: './header.component.html',
11 styleUrls: [ './header.component.scss' ]
12})
13
14export class HeaderComponent implements OnInit {
15 searchValue = ''
16
17 constructor (
18 private router: Router,
19 private auth: AuthService
20 ) {}
21
22 ngOnInit () {
23 this.router.events
24 .pipe(
25 filter(e => e instanceof NavigationEnd),
26 map(() => getParameterByName('search', window.location.href))
27 )
28 .subscribe(searchQuery => this.searchValue = searchQuery || '')
29 }
30
31 doSearch () {
32 const queryParams: any = {
33 search: this.searchValue
34 }
35
36 const o = this.auth.isLoggedIn()
37 ? this.loadUserLanguages(queryParams)
38 : of(true)
39
40 o.subscribe(() => this.router.navigate([ '/search' ], { queryParams }))
41 }
42
43 private loadUserLanguages (queryParams: any) {
44 return this.auth.userInformationLoaded
45 .pipe(
46 first(),
47 tap(() => Object.assign(queryParams, { languageOneOf: this.auth.getUser().videoLanguages }))
48 )
49 }
50}