X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fapp%2Fheader%2Fsearch-typeahead.component.ts;h=2bf1072f443b1ce9752e80b0e5292e818a5fd56e;hb=36004aa7b0de5cb69a452090770221b192a78eb8;hp=372601fa82c2c6a5fee8332d73143dc77aacce87;hpb=4c1c17093461b58d3ee3f23f239e340d8dac1149;p=github%2FChocobozzz%2FPeerTube.git diff --git a/client/src/app/header/search-typeahead.component.ts b/client/src/app/header/search-typeahead.component.ts index 372601fa8..2bf1072f4 100644 --- a/client/src/app/header/search-typeahead.component.ts +++ b/client/src/app/header/search-typeahead.component.ts @@ -35,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 => this.isOnSearch() && params.search !== undefined && params.search !== null)) + .subscribe(params => this.search = params.search) this.serverService.getConfig() .subscribe(config => this.serverConfig = config) } @@ -134,7 +134,7 @@ export class SearchTypeaheadComponent implements OnInit, OnDestroy { ) } - handleKeyUp (event: KeyboardEvent) { + handleKey (event: KeyboardEvent) { event.stopImmediatePropagation() if (!this.keyboardEventsManager) return @@ -143,17 +143,18 @@ export class SearchTypeaheadComponent implements OnInit, OnDestroy { case 'ArrowUp': this.keyboardEventsManager.onKeydown(event) break - case 'Enter': - this.newSearch = false - this.doSearch() - break } } + isOnSearch () { + return window.location.pathname === '/search' + } + doSearch () { + this.newSearch = false const queryParams: Params = {} - if (window.location.pathname === '/search' && this.route.snapshot.queryParams) { + if (this.isOnSearch() && this.route.snapshot.queryParams) { Object.assign(queryParams, this.route.snapshot.queryParams) }