Clearing the search bar when switching accounts (#2685)
* Clearing the search bar when switching accounts * Fixing Lint Issues and Prettier * Updating the message to use switchAccount instead of a new message name "clearSearchBarText" * Updating to use Observable on activeAccount * adding back line * adding back line * Adding OnInit OnDestroy
This commit is contained in:
parent
6e5cf10a99
commit
60b39bc211
|
@ -1,17 +1,19 @@
|
||||||
import { Component } from "@angular/core";
|
import { Component, OnDestroy, OnInit } from "@angular/core";
|
||||||
import { FormControl } from "@angular/forms";
|
import { FormControl } from "@angular/forms";
|
||||||
|
|
||||||
|
import { StateService } from "jslib-common/abstractions/state.service";
|
||||||
|
|
||||||
import { SearchBarService, SearchBarState } from "./search-bar.service";
|
import { SearchBarService, SearchBarState } from "./search-bar.service";
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: "app-search",
|
selector: "app-search",
|
||||||
templateUrl: "search.component.html",
|
templateUrl: "search.component.html",
|
||||||
})
|
})
|
||||||
export class SearchComponent {
|
export class SearchComponent implements OnInit, OnDestroy {
|
||||||
state: SearchBarState;
|
state: SearchBarState;
|
||||||
searchText: FormControl = new FormControl(null);
|
searchText: FormControl = new FormControl(null);
|
||||||
|
|
||||||
constructor(private searchBarService: SearchBarService) {
|
constructor(private searchBarService: SearchBarService, private stateService: StateService) {
|
||||||
this.searchBarService.state.subscribe((state) => {
|
this.searchBarService.state.subscribe((state) => {
|
||||||
this.state = state;
|
this.state = state;
|
||||||
});
|
});
|
||||||
|
@ -20,4 +22,15 @@ export class SearchComponent {
|
||||||
this.searchBarService.setSearchText(value);
|
this.searchBarService.setSearchText(value);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ngOnInit() {
|
||||||
|
this.stateService.activeAccount.subscribe((value) => {
|
||||||
|
this.searchBarService.setSearchText("");
|
||||||
|
this.searchText.patchValue("");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
ngOnDestroy() {
|
||||||
|
this.stateService.activeAccount.unsubscribe();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue