X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fapp%2Fshared%2Fshared-main%2Fmisc%2Fsimple-search-input.component.ts;h=99abb94e7fa35f4c27f9f23160399a621fe9046b;hb=34ba86a8b481e0071c5253fcd562911a48688352;hp=224d71134535697db729c6034cd82b6c12c149ec;hpb=67264e060b6068399dae9a67abae035a73b84af1;p=github%2FChocobozzz%2FPeerTube.git diff --git a/client/src/app/shared/shared-main/misc/simple-search-input.component.ts b/client/src/app/shared/shared-main/misc/simple-search-input.component.ts index 224d71134..99abb94e7 100644 --- a/client/src/app/shared/shared-main/misc/simple-search-input.component.ts +++ b/client/src/app/shared/shared-main/misc/simple-search-input.component.ts @@ -1,10 +1,7 @@ -import { Subject } from 'rxjs' -import { debounceTime, distinctUntilChanged } from 'rxjs/operators' import { Component, ElementRef, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core' -import { ActivatedRoute, Router } from '@angular/router' @Component({ - selector: 'simple-search-input', + selector: 'my-simple-search-input', templateUrl: './simple-search-input.component.html', styleUrls: [ './simple-search-input.component.scss' ] }) @@ -22,23 +19,9 @@ export class SimpleSearchInputComponent implements OnInit { value = '' inputShown: boolean - private searchSubject = new Subject() - - constructor ( - private router: Router, - private route: ActivatedRoute - ) {} + private hasAlreadySentSearch = false ngOnInit () { - this.searchSubject - .pipe( - debounceTime(400), - distinctUntilChanged() - ) - .subscribe(value => this.searchChanged.emit(value)) - - this.searchSubject.next(this.value) - if (this.isInputShown()) this.showInput(false) } @@ -54,7 +37,7 @@ export class SimpleSearchInputComponent implements OnInit { return } - this.searchChange() + this.sendSearch() } showInput (focus = true) { @@ -80,9 +63,14 @@ export class SimpleSearchInputComponent implements OnInit { this.hideInput() } - searchChange () { - this.router.navigate([ './search' ], { relativeTo: this.route }) + sendSearch () { + this.hasAlreadySentSearch = true + this.searchChanged.emit(this.value) + } + + onResetFilter () { + this.value = '' - this.searchSubject.next(this.value) + if (this.hasAlreadySentSearch) this.sendSearch() } }