1 import { filter, first, map, tap } from 'rxjs/operators'
2 import { Component, OnInit } from '@angular/core'
3 import { NavigationEnd, Router } from '@angular/router'
4 import { getParameterByName } from '../shared/misc/utils'
5 import { AuthService } from '@app/core'
6 import { of } from 'rxjs'
10 templateUrl: './header.component.html',
11 styleUrls: [ './header.component.scss' ]
14 export class HeaderComponent implements OnInit {
18 private router: Router,
19 private auth: AuthService
25 filter(e => e instanceof NavigationEnd),
26 map(() => getParameterByName('search', window.location.href))
28 .subscribe(searchQuery => this.searchValue = searchQuery || '')
32 const queryParams: any = {
33 search: this.searchValue
36 const o = this.auth.isLoggedIn()
37 ? this.loadUserLanguages(queryParams)
40 o.subscribe(() => this.router.navigate([ '/search' ], { queryParams }))
43 private loadUserLanguages (queryParams: any) {
44 return this.auth.userInformationLoaded
47 tap(() => Object.assign(queryParams, { languageOneOf: this.auth.getUser().videoLanguages }))