From 59726ad81819d59da0342fda4abce4368459ea10 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Wed, 31 Jan 2018 17:20:27 -0500 Subject: [PATCH] refresh ciphers list on add/edit/delete --- src/app/vault/add-edit.component.ts | 1 + src/app/vault/ciphers.component.ts | 24 ++---------------------- src/app/vault/vault.component.ts | 8 ++++---- 3 files changed, 7 insertions(+), 26 deletions(-) diff --git a/src/app/vault/add-edit.component.ts b/src/app/vault/add-edit.component.ts index 1141370f..9a12c670 100644 --- a/src/app/vault/add-edit.component.ts +++ b/src/app/vault/add-edit.component.ts @@ -142,6 +142,7 @@ export class AddEditComponent implements OnChanges { try { this.formPromise = this.cipherService.saveWithServer(cipher); await this.formPromise; + this.cipher.id = cipher.id; this.analytics.eventTrack.next({ action: this.editMode ? 'Edited Cipher' : 'Added Cipher' }); this.toasterService.popAsync('success', null, this.i18nService.t(this.editMode ? 'editedItem' : 'addedItem')); this.onSavedCipher.emit(this.cipher); diff --git a/src/app/vault/ciphers.component.ts b/src/app/vault/ciphers.component.ts index 0e7ef771..1dc7010e 100644 --- a/src/app/vault/ciphers.component.ts +++ b/src/app/vault/ciphers.component.ts @@ -4,7 +4,6 @@ import { Component, EventEmitter, Input, - OnInit, Output, } from '@angular/core'; @@ -16,7 +15,7 @@ import { CipherService } from 'jslib/abstractions/cipher.service'; selector: 'app-vault-ciphers', template: template, }) -export class CiphersComponent implements OnInit { +export class CiphersComponent { @Input() activeCipherId: string = null; @Output() onCipherClicked = new EventEmitter(); @Output() onAddCipher = new EventEmitter(); @@ -26,12 +25,7 @@ export class CiphersComponent implements OnInit { searchPlaceholder: string = null; private filter: (cipher: CipherView) => boolean = null; - constructor(private cipherService: CipherService) { - } - - async ngOnInit() { - //await this.load(); - } + constructor(private cipherService: CipherService) {} async load(filter: (cipher: CipherView) => boolean = null) { this.filter = filter; @@ -48,20 +42,6 @@ export class CiphersComponent implements OnInit { await this.load(this.filter); } - updateCipher(cipher: CipherView) { - const i = this.ciphers.findIndex((c) => c.id === cipher.id); - if (i > -1) { - this.ciphers[i] = cipher; - } - } - - removeCipher(cipherId: string) { - const i = this.ciphers.findIndex((c) => c.id === cipherId); - if (i > -1) { - this.ciphers.splice(i, 1); - } - } - cipherClicked(cipher: CipherView) { this.onCipherClicked.emit(cipher); } diff --git a/src/app/vault/vault.component.ts b/src/app/vault/vault.component.ts index 2c8a3839..992aa880 100644 --- a/src/app/vault/vault.component.ts +++ b/src/app/vault/vault.component.ts @@ -119,18 +119,18 @@ export class VaultComponent implements OnInit { this.go(); } - savedCipher(cipher: CipherView) { + async savedCipher(cipher: CipherView) { this.cipherId = cipher.id; this.action = 'view'; this.go(); - this.ciphersComponent.updateCipher(cipher); + await this.ciphersComponent.refresh(); } - deletedCipher(cipher: CipherView) { + async deletedCipher(cipher: CipherView) { this.cipherId = null; this.action = null; this.go(); - this.ciphersComponent.removeCipher(cipher.id); + await this.ciphersComponent.refresh(); } editCipherAttachments(cipher: CipherView) {