Merge pull request #1105 from BO41/unused-imports
[oweals/peertube.git] / client / src / app / header / header.component.ts
index a903048f234188a15f04acabc846c5ce0e687a22..f73d40947187c630606f28d13ab6185a39471c53 100644 (file)
@@ -1,5 +1,6 @@
+import { filter, map } from 'rxjs/operators'
 import { Component, OnInit } from '@angular/core'
-import { Router } from '@angular/router'
+import { NavigationEnd, Router } from '@angular/router'
 import { getParameterByName } from '../shared/misc/utils'
 
 @Component({
@@ -14,14 +15,16 @@ export class HeaderComponent implements OnInit {
   constructor (private router: Router) {}
 
   ngOnInit () {
-    const searchQuery = getParameterByName('search', window.location.href)
-    if (searchQuery) this.searchValue = searchQuery
+    this.router.events
+        .pipe(
+          filter(e => e instanceof NavigationEnd),
+          map(() => getParameterByName('search', window.location.href))
+        )
+        .subscribe(searchQuery => this.searchValue = searchQuery || '')
   }
 
   doSearch () {
-    if (!this.searchValue) return
-
-    this.router.navigate([ '/videos', 'search' ], {
+    this.router.navigate([ '/search' ], {
       queryParams: { search: this.searchValue }
     })
   }