]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/header/search-typeahead.component.ts
Fix search after first type on input
[github/Chocobozzz/PeerTube.git] / client / src / app / header / search-typeahead.component.ts
index 210a1474cbfa5aca191ece43a9e825bac437e20b..d0350368dab790bd80ff089e1b84a32ae0b101e4 100644 (file)
@@ -1,17 +1,9 @@
-import {
-  Component,
-  OnInit,
-  OnDestroy,
-  QueryList,
-  ViewChild,
-  ElementRef
-} from '@angular/core'
-import { Router, Params, ActivatedRoute } from '@angular/router'
+import { Component, ElementRef, OnDestroy, OnInit, QueryList, ViewChild } from '@angular/core'
+import { ActivatedRoute, Params, Router } from '@angular/router'
 import { AuthService, ServerService } from '@app/core'
 import { first, tap } from 'rxjs/operators'
 import { ListKeyManager } from '@angular/cdk/a11y'
-import { UP_ARROW, DOWN_ARROW, ENTER } from '@angular/cdk/keycodes'
-import { SuggestionComponent, Result } from './suggestion.component'
+import { Result, SuggestionComponent } from './suggestion.component'
 import { of } from 'rxjs'
 import { ServerConfig } from '@shared/models'
 
@@ -43,9 +35,9 @@ export class SearchTypeaheadComponent implements OnInit, OnDestroy {
   ) {}
 
   ngOnInit () {
-    const query = this.route.snapshot.queryParams
-    if (query['search']) this.search = query['search']
-
+    this.route.queryParams
+      .pipe(first(params => params.search !== undefined && params.search !== null))
+      .subscribe(params => this.search = params.search)
     this.serverService.getConfig()
       .subscribe(config => this.serverConfig = config)
   }
@@ -142,23 +134,20 @@ export class SearchTypeaheadComponent implements OnInit, OnDestroy {
     )
   }
 
-  handleKeyUp (event: KeyboardEvent) {
+  handleKey (event: KeyboardEvent) {
     event.stopImmediatePropagation()
     if (!this.keyboardEventsManager) return
-    
+
     switch (event.key) {
-      case "ArrowDown":
-      case "ArrowUp":
+      case 'ArrowDown':
+      case 'ArrowUp':
         this.keyboardEventsManager.onKeydown(event)
         break
-      case "Enter":
-        this.newSearch = false
-        this.doSearch()
-        break
     }
   }
 
   doSearch () {
+    this.newSearch = false
     const queryParams: Params = {}
 
     if (window.location.pathname === '/search' && this.route.snapshot.queryParams) {