From 60b39bc211e79c02ca53305eee4874fd20ed5531 Mon Sep 17 00:00:00 2001 From: CarleyDiaz-Bitwarden <103955722+CarleyDiaz-Bitwarden@users.noreply.github.com> Date: Mon, 23 May 2022 14:04:19 -0400 Subject: [PATCH] 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 --- .../src/app/layout/search/search.component.ts | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/apps/desktop/src/app/layout/search/search.component.ts b/apps/desktop/src/app/layout/search/search.component.ts index c18ce729c8..9e2bab6565 100644 --- a/apps/desktop/src/app/layout/search/search.component.ts +++ b/apps/desktop/src/app/layout/search/search.component.ts @@ -1,17 +1,19 @@ -import { Component } from "@angular/core"; +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 { +export class SearchComponent implements OnInit, OnDestroy { state: SearchBarState; searchText: FormControl = new FormControl(null); - constructor(private searchBarService: SearchBarService) { + constructor(private searchBarService: SearchBarService, private stateService: StateService) { this.searchBarService.state.subscribe((state) => { this.state = state; }); @@ -20,4 +22,15 @@ export class SearchComponent { this.searchBarService.setSearchText(value); }); } + + ngOnInit() { + this.stateService.activeAccount.subscribe((value) => { + this.searchBarService.setSearchText(""); + this.searchText.patchValue(""); + }); + } + + ngOnDestroy() { + this.stateService.activeAccount.unsubscribe(); + } }