Skip to content

Commit

Permalink
feat: show protected warning after protecting a note without protections
Browse files Browse the repository at this point in the history
  • Loading branch information
arielsvg committed Mar 22, 2021
1 parent bf6cfa3 commit 9f5c640
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
4 changes: 2 additions & 2 deletions app/assets/javascripts/views/editor/editor-view.pug
Original file line number Diff line number Diff line change
@@ -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.note.protected && !self.state.showEditor'
ng-if='self.state.showProtectedWarning'
app-state='self.appState'
on-view-note='self.dismissProtectedWarning()'
)
.flex-grow.flex.flex-col(
ng-if='self.state.showEditor'
ng-if='!self.state.showProtectedWarning'
)
.sn-component
.sk-app-bar.no-edges(
Expand Down
22 changes: 9 additions & 13 deletions app/assets/javascripts/views/editor/editor_view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ type EditorState = {
textareaUnloading: boolean
/** Fields that can be directly mutated by the template */
mutable: any
showEditor: boolean
showProtectedWarning: boolean
}

type EditorValues = {
Expand Down Expand Up @@ -225,7 +225,7 @@ class EditorViewCtrl extends PureViewCtrl<unknown, EditorState> {
mutable: {
tagsString: ''
},
showEditor: false,
showProtectedWarning: false,
} as EditorState;
}

Expand Down Expand Up @@ -275,15 +275,15 @@ class EditorViewCtrl extends PureViewCtrl<unknown, EditorState> {
async handleEditorNoteChange() {
this.cancelPendingSetStatus();
const note = this.editor.note;
const showEditor = !note.protected;
const showProtectedWarning = note.protected && !this.application.hasProtectionSources();
await this.setState({
showActionsMenu: false,
showOptionsMenu: false,
showEditorMenu: false,
showHistoryMenu: false,
altKeyDown: false,
noteStatus: undefined,
showEditor,
showProtectedWarning,
});
this.editorValues.title = note.title;
this.editorValues.text = note.text;
Expand All @@ -292,14 +292,14 @@ class EditorViewCtrl extends PureViewCtrl<unknown, EditorState> {
this.reloadPreferences();
this.reloadStackComponents();
this.reloadNoteTagsComponent();
if (note.safeText().length === 0 && showEditor) {
if (note.safeText().length === 0 && !showProtectedWarning) {
this.focusTitle();
}
}

async dismissProtectedWarning() {
await this.setState({
showEditor: true
showProtectedWarning: false
});
this.focusTitle();
}
Expand Down Expand Up @@ -730,13 +730,9 @@ class EditorViewCtrl extends PureViewCtrl<unknown, EditorState> {
} 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);
}
this.setState({
showProtectedWarning: true
});
}
}
}
Expand Down

0 comments on commit 9f5c640

Please sign in to comment.