feat: add protect option to menu

This commit is contained in:
Antonella Sgarlatta
2021-05-11 17:09:23 -03:00
parent b3380cf323
commit 8302733a49
6 changed files with 80 additions and 35 deletions

View File

@@ -1,11 +1,11 @@
#editor-column.section.editor.sn-component(aria-label='Note')
protected-note-panel.h-full.flex.justify-center.items-center(
ng-if='self.state.showProtectedWarning'
ng-if='self.appState.notes.showProtectedWarning'
app-state='self.appState'
on-view-note='self.dismissProtectedWarning()'
)
.flex-grow.flex.flex-col(
ng-if='!self.state.showProtectedWarning'
ng-if='!self.appState.notes.showProtectedWarning'
)
.sn-component
.sk-app-bar.no-edges(

View File

@@ -85,7 +85,6 @@ type EditorState = {
textareaUnloading: boolean;
/** Fields that can be directly mutated by the template */
mutable: any;
showProtectedWarning: boolean;
};
type EditorValues = {
@@ -241,7 +240,6 @@ class EditorViewCtrl extends PureViewCtrl<unknown, EditorState> {
mutable: {
tagsString: '',
},
showProtectedWarning: false,
} as EditorState;
}
@@ -291,8 +289,8 @@ class EditorViewCtrl extends PureViewCtrl<unknown, EditorState> {
async handleEditorNoteChange() {
this.cancelPendingSetStatus();
const note = this.editor.note;
const showProtectedWarning =
note.protected && !this.application.hasProtectionSources();
const showProtectedWarning = note.protected && !this.application.hasProtectionSources();
this.setShowProtectedWarning(showProtectedWarning);
await this.setState({
showActionsMenu: false,
showOptionsMenu: false,
@@ -300,7 +298,6 @@ class EditorViewCtrl extends PureViewCtrl<unknown, EditorState> {
showHistoryMenu: false,
altKeyDown: false,
noteStatus: undefined,
showProtectedWarning,
});
this.editorValues.title = note.title;
this.editorValues.text = note.text;
@@ -318,9 +315,7 @@ class EditorViewCtrl extends PureViewCtrl<unknown, EditorState> {
}
async dismissProtectedWarning() {
await this.setState({
showProtectedWarning: false,
});
this.setShowProtectedWarning(false);
this.focusTitle();
}
@@ -658,6 +653,10 @@ class EditorViewCtrl extends PureViewCtrl<unknown, EditorState> {
}
}
setShowProtectedWarning(show: boolean) {
this.application.getAppState().notes.setShowProtectedWarning(show);
}
async deleteNote(permanently: boolean) {
if (this.editor.isTemplateNote) {
this.application.alertService!.alert(STRING_DELETE_PLACEHOLDER_ATTEMPT);
@@ -767,9 +766,7 @@ class EditorViewCtrl extends PureViewCtrl<unknown, EditorState> {
} else {
const note = await this.application.protectNote(this.note);
if (note?.protected && !this.application.hasProtectionSources()) {
this.setState({
showProtectedWarning: true,
});
this.setShowProtectedWarning(true);
}
}
}