From a3f73ba6645372a1be6628aa5c23e2d8c4d00534 Mon Sep 17 00:00:00 2001 From: Baptiste Grob <60621355+baptiste-grob@users.noreply.github.com> Date: Tue, 23 Feb 2021 10:40:08 +0100 Subject: [PATCH] feat: make unprotecting a note a protected action --- .../javascripts/views/editor/editor_view.ts | 26 +++++++++---------- package.json | 2 +- yarn.lock | 8 +++--- 3 files changed, 17 insertions(+), 19 deletions(-) diff --git a/app/assets/javascripts/views/editor/editor_view.ts b/app/assets/javascripts/views/editor/editor_view.ts index 5fca2e50e..f5ed13f1a 100644 --- a/app/assets/javascripts/views/editor/editor_view.ts +++ b/app/assets/javascripts/views/editor/editor_view.ts @@ -714,20 +714,18 @@ class EditorViewCtrl extends PureViewCtrl { } async toggleProtectNote() { - const note = await this.application.changeAndSaveItem( - this.note.uuid, - (mutator) => { - mutator.protected = !this.note.protected; - }, - false - ); - if (note?.protected && !this.application.hasProtectionSources()) { - if (await confirmDialog({ - text: Strings.protectingNoteWithoutProtectionSources, - confirmButtonText: Strings.openAccountMenu, - confirmButtonStyle: 'info', - })) { - this.appState.accountMenu.setShow(true); + if (this.note.protected) { + void this.application.unprotectNote(this.note); + } else { + const note = await this.application.protectNote(this.note); + if (note?.protected && !this.application.hasProtectionSources()) { + if (await confirmDialog({ + text: Strings.protectingNoteWithoutProtectionSources, + confirmButtonText: Strings.openAccountMenu, + confirmButtonStyle: 'info', + })) { + this.appState.accountMenu.setShow(true); + } } } } diff --git a/package.json b/package.json index 25a958730..5537d4f98 100644 --- a/package.json +++ b/package.json @@ -68,7 +68,7 @@ "@reach/alert-dialog": "^0.13.0", "@reach/dialog": "^0.13.0", "@standardnotes/sncrypto-web": "^1.2.10", - "@standardnotes/snjs": "^2.0.57", + "@standardnotes/snjs": "^2.0.58", "mobx": "^6.1.6", "preact": "^10.5.12" } diff --git a/yarn.lock b/yarn.lock index c5287e1bd..21cf08f3b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1845,10 +1845,10 @@ "@standardnotes/sncrypto-common" "^1.2.7" libsodium-wrappers "^0.7.8" -"@standardnotes/snjs@^2.0.57": - version "2.0.57" - resolved "https://registry.yarnpkg.com/@standardnotes/snjs/-/snjs-2.0.57.tgz#758d30d9074aa463ca2b642783d929a10a1a1c9f" - integrity sha512-s2FP024TziZnt0nJ10Tbja3IQ2KOITA67EGchadAN+vapXEicTDX2MSCPzlvk2D1M494zu15vWwQX1ryeHvHHA== +"@standardnotes/snjs@^2.0.58": + version "2.0.58" + resolved "https://registry.yarnpkg.com/@standardnotes/snjs/-/snjs-2.0.58.tgz#b3cc340699effd9ab2b55e48eb84745f71e058cb" + integrity sha512-eJnCpwTpI55RM916xjdgcGdzIcgaGJQ5EeykKvLxD4Oy7FRPfQnZc5hCp4LbeZvdlQQze+E2gH1nY77zPDsVXw== dependencies: "@standardnotes/sncrypto-common" "^1.2.9"