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:
CarleyDiaz-Bitwarden 2022-05-23 14:04:19 -04:00 committed by GitHub
parent 6e5cf10a99
commit 60b39bc211
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 3 deletions

View File

@ -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();
}
} }