diff options
Diffstat (limited to 'client/src/app/shared/shared-main/misc/simple-search-input.component.ts')
-rw-r--r-- | client/src/app/shared/shared-main/misc/simple-search-input.component.ts | 32 |
1 files changed, 10 insertions, 22 deletions
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 292ec4c82..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,7 +1,4 @@ | |||
1 | import { Subject } from 'rxjs' | ||
2 | import { debounceTime, distinctUntilChanged } from 'rxjs/operators' | ||
3 | import { Component, ElementRef, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core' | 1 | import { Component, ElementRef, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core' |
4 | import { ActivatedRoute, Router } from '@angular/router' | ||
5 | 2 | ||
6 | @Component({ | 3 | @Component({ |
7 | selector: 'my-simple-search-input', | 4 | selector: 'my-simple-search-input', |
@@ -22,23 +19,9 @@ export class SimpleSearchInputComponent implements OnInit { | |||
22 | value = '' | 19 | value = '' |
23 | inputShown: boolean | 20 | inputShown: boolean |
24 | 21 | ||
25 | private searchSubject = new Subject<string>() | 22 | private hasAlreadySentSearch = false |
26 | |||
27 | constructor ( | ||
28 | private router: Router, | ||
29 | private route: ActivatedRoute | ||
30 | ) {} | ||
31 | 23 | ||
32 | ngOnInit () { | 24 | ngOnInit () { |
33 | this.searchSubject | ||
34 | .pipe( | ||
35 | debounceTime(400), | ||
36 | distinctUntilChanged() | ||
37 | ) | ||
38 | .subscribe(value => this.searchChanged.emit(value)) | ||
39 | |||
40 | this.searchSubject.next(this.value) | ||
41 | |||
42 | if (this.isInputShown()) this.showInput(false) | 25 | if (this.isInputShown()) this.showInput(false) |
43 | } | 26 | } |
44 | 27 | ||
@@ -54,7 +37,7 @@ export class SimpleSearchInputComponent implements OnInit { | |||
54 | return | 37 | return |
55 | } | 38 | } |
56 | 39 | ||
57 | this.searchChange() | 40 | this.sendSearch() |
58 | } | 41 | } |
59 | 42 | ||
60 | showInput (focus = true) { | 43 | showInput (focus = true) { |
@@ -80,9 +63,14 @@ export class SimpleSearchInputComponent implements OnInit { | |||
80 | this.hideInput() | 63 | this.hideInput() |
81 | } | 64 | } |
82 | 65 | ||
83 | searchChange () { | 66 | sendSearch () { |
84 | this.router.navigate([ './search' ], { relativeTo: this.route }) | 67 | this.hasAlreadySentSearch = true |
68 | this.searchChanged.emit(this.value) | ||
69 | } | ||
70 | |||
71 | onResetFilter () { | ||
72 | this.value = '' | ||
85 | 73 | ||
86 | this.searchSubject.next(this.value) | 74 | if (this.hasAlreadySentSearch) this.sendSearch() |
87 | } | 75 | } |
88 | } | 76 | } |