From bc5cec82cc153f2f391bc6dce61735696589dbba Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Mon, 29 Oct 2018 09:29:21 -0400 Subject: [PATCH] control applying saved state and when to show groupings --- src/popup/app.component.ts | 6 +-- src/popup/vault/ciphers.component.html | 64 +++++++++++++------------- src/popup/vault/ciphers.component.ts | 20 ++++++-- 3 files changed, 52 insertions(+), 38 deletions(-) diff --git a/src/popup/app.component.ts b/src/popup/app.component.ts index 8a4376270f..eedb063731 100644 --- a/src/popup/app.component.ts +++ b/src/popup/app.component.ts @@ -59,7 +59,6 @@ export class AppComponent implements OnInit { }); private lastActivity: number = null; - private previousUrl: string = ''; constructor(private angulartics2GoogleAnalytics: Angulartics2GoogleAnalytics, private analytics: Angulartics2, private toasterService: ToasterService, private storageService: StorageService, @@ -124,14 +123,15 @@ export class AppComponent implements OnInit { this.router.events.subscribe((event) => { if (event instanceof NavigationEnd) { const url = event.urlAfterRedirects || event.url || ''; - if (url.startsWith('/tabs/') && this.previousUrl.startsWith('/tabs/')) { + if (url.startsWith('/tabs/') && (window as any).previousPopupUrl != null && + (window as any).previousPopupUrl.startsWith('/tabs/')) { this.stateService.remove('GroupingsComponent'); this.stateService.remove('CiphersComponent'); } if (url.startsWith('/tabs/')) { this.stateService.remove('addEditCipher'); } - this.previousUrl = url; + (window as any).previousPopupUrl = url; // Clear route direction after animation (400ms) if ((window as any).routeDirection != null) { diff --git a/src/popup/vault/ciphers.component.html b/src/popup/vault/ciphers.component.html index f4530563be..83066f5f07 100644 --- a/src/popup/vault/ciphers.component.html +++ b/src/popup/vault/ciphers.component.html @@ -16,40 +16,42 @@ - -
-
- {{'folders' | i18n}} -
-
- - -
-
- {{'collections' | i18n}} +
+
+ {{'collections' | i18n}} +
+
- -
+
diff --git a/src/popup/vault/ciphers.component.ts b/src/popup/vault/ciphers.component.ts index eb4c52eeca..eb9f0941e7 100644 --- a/src/popup/vault/ciphers.component.ts +++ b/src/popup/vault/ciphers.component.ts @@ -56,6 +56,7 @@ export class CiphersComponent extends BaseCiphersComponent implements OnInit, On private selectedTimeout: number; private preventSelected = false; private pageSize = 100; + private applySavedState = true; constructor(searchService: SearchService, private route: ActivatedRoute, private router: Router, private location: Location, @@ -66,6 +67,8 @@ export class CiphersComponent extends BaseCiphersComponent implements OnInit, On private analytics: Angulartics2, private platformUtilsService: PlatformUtilsService) { super(searchService); this.pageSize = platformUtilsService.isEdge() ? 25 : 100; + this.applySavedState = (window as any).previousPopupUrl != null && + !(window as any).previousPopupUrl.startsWith('/ciphers'); } async ngOnInit() { @@ -120,11 +123,14 @@ export class CiphersComponent extends BaseCiphersComponent implements OnInit, On } this.loadMore(); - this.state = (await this.stateService.get(ComponentId)) || {}; - if (this.state.searchText) { - this.searchText = this.state.searchText; + if (this.applySavedState) { + this.state = (await this.stateService.get(ComponentId)) || {}; + if (this.state.searchText) { + this.searchText = this.state.searchText; + } + window.setTimeout(() => this.popupUtils.setContentScrollY(window, this.state.scrollY), 0); } - window.setTimeout(() => this.popupUtils.setContentScrollY(window, this.state.scrollY), 0); + this.stateService.remove(ComponentId); }); this.broadcasterService.subscribe(ComponentId, (message: any) => { @@ -209,6 +215,12 @@ export class CiphersComponent extends BaseCiphersComponent implements OnInit, On this.didScroll = this.pagedCiphers.length > this.pageSize; } + showGroupings() { + return !this.isSearching() && + ((this.nestedFolders && this.nestedFolders.length) || + (this.nestedCollections && this.nestedCollections.length)); + } + isSearching() { return !this.searchPending && this.searchService.isSearchable(this.searchText); }