feat: make unprotecting a note a protected action

This commit is contained in:
Baptiste Grob
2021-02-23 10:40:08 +01:00
parent ef3a962d78
commit a3f73ba664
3 changed files with 17 additions and 19 deletions

View File

@@ -714,20 +714,18 @@ class EditorViewCtrl extends PureViewCtrl<unknown, EditorState> {
}
async toggleProtectNote() {
const note = await this.application.changeAndSaveItem<NoteMutator>(
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);
}
}
}
}