1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-28 22:23:28 +00:00
Files
browser/apps/desktop/src/app/layout/search/search.component.ts
CarleyDiaz-Bitwarden 60b39bc211 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
2022-05-23 14:04:19 -04:00

37 lines
1.0 KiB
TypeScript

import { Component, OnDestroy, OnInit } from "@angular/core";
import { FormControl } from "@angular/forms";
import { StateService } from "jslib-common/abstractions/state.service";
import { SearchBarService, SearchBarState } from "./search-bar.service";
@Component({
selector: "app-search",
templateUrl: "search.component.html",
})
export class SearchComponent implements OnInit, OnDestroy {
state: SearchBarState;
searchText: FormControl = new FormControl(null);
constructor(private searchBarService: SearchBarService, private stateService: StateService) {
this.searchBarService.state.subscribe((state) => {
this.state = state;
});
this.searchText.valueChanges.subscribe((value) => {
this.searchBarService.setSearchText(value);
});
}
ngOnInit() {
this.stateService.activeAccount.subscribe((value) => {
this.searchBarService.setSearchText("");
this.searchText.patchValue("");
});
}
ngOnDestroy() {
this.stateService.activeAccount.unsubscribe();
}
}