]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - 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
a5f8b0b4 1import { filter, first, map, tap } from 'rxjs/operators'
f3aaa9a9 2import { Component, OnInit } from '@angular/core'
db400f44 3import { NavigationEnd, Router } from '@angular/router'
f3aaa9a9 4import { getParameterByName } from '../shared/misc/utils'
a5f8b0b4
C
5import { AuthService } from '@app/core'
6import { of } from 'rxjs'
f3aaa9a9
C
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
a5f8b0b4
C
17 constructor (
18 private router: Router,
19 private auth: AuthService
20 ) {}
f3aaa9a9
C
21
22 ngOnInit () {
66dc5907 23 this.router.events
db400f44
C
24 .pipe(
25 filter(e => e instanceof NavigationEnd),
ff644b30 26 map(() => getParameterByName('search', window.location.href))
db400f44 27 )
ff644b30 28 .subscribe(searchQuery => this.searchValue = searchQuery || '')
f3aaa9a9
C
29 }
30
31 doSearch () {
a5f8b0b4
C
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 )
f3aaa9a9
C
49 }
50}