From 1275a2e148fad91f237ae48b24d427155925b522 Mon Sep 17 00:00:00 2001 From: Aman Harwara Date: Wed, 13 Sep 2023 16:50:35 +0530 Subject: [PATCH] chore: remember previous multiple vault selection when switching back from single to multiple --- .../src/Vaults/VaultDisplayService.ts | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/packages/ui-services/src/Vaults/VaultDisplayService.ts b/packages/ui-services/src/Vaults/VaultDisplayService.ts index 75c20aaa4..40208bae8 100644 --- a/packages/ui-services/src/Vaults/VaultDisplayService.ts +++ b/packages/ui-services/src/Vaults/VaultDisplayService.ts @@ -13,7 +13,12 @@ import { StorageKey, VaultLockServiceEvent, } from '@standardnotes/services' -import { VaultDisplayOptions, VaultDisplayOptionsPersistable, VaultListingInterface } from '@standardnotes/models' +import { + ExclusionaryOptions, + VaultDisplayOptions, + VaultDisplayOptionsPersistable, + VaultListingInterface, +} from '@standardnotes/models' import { VaultDisplayServiceEvent } from './VaultDisplayServiceEvent' import { AbstractUIService } from '../Abstract/AbstractUIService' import { WebApplicationInterface } from '../WebApplication/WebApplicationInterface' @@ -25,6 +30,7 @@ export class VaultDisplayService extends AbstractUIService implements VaultDisplayServiceInterface, InternalEventHandlerInterface { + previousMultipleSelectionOptions?: VaultDisplayOptions options: VaultDisplayOptions public exclusivelyShownVault: VaultListingInterface | undefined = undefined @@ -101,10 +107,14 @@ export class VaultDisplayService const vaults = this.application.vaults.getVaults() const lockedVaults = this.application.vaultLocks.getLockedvaults() + const exclude = this.previousMultipleSelectionOptions + ? (this.previousMultipleSelectionOptions.getOptions() as ExclusionaryOptions).exclude + : vaults + .map((vault) => vault.systemIdentifier) + .filter((identifier) => identifier !== this.exclusivelyShownVault?.systemIdentifier) + const newOptions = new VaultDisplayOptions({ - exclude: vaults - .map((vault) => vault.systemIdentifier) - .filter((identifier) => identifier !== this.exclusivelyShownVault?.systemIdentifier), + exclude, locked: lockedVaults.map((vault) => vault.systemIdentifier), }) @@ -187,8 +197,16 @@ export class VaultDisplayService } private setVaultSelectionOptions = (options: VaultDisplayOptions) => { + const previousOptions = this.options this.options = options + const changingFromMultipleToExclusive = + !previousOptions.isInExclusiveDisplayMode() && options.isInExclusiveDisplayMode() + + if (changingFromMultipleToExclusive) { + this.previousMultipleSelectionOptions = previousOptions + } + if (this.isInExclusiveDisplayMode()) { this.exclusivelyShownVault = this.application.vaults.getVault({ keySystemIdentifier: this.options.getExclusivelyShownVault(),