Skip to content

Commit

Permalink
fix: more accurate saving status + dont allow editor change while not…
Browse files Browse the repository at this point in the history
…e is locked
  • Loading branch information
moughxyz committed Apr 21, 2021
1 parent 64945ab commit b93a35f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
2 changes: 2 additions & 0 deletions app/assets/javascripts/strings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ export const STRING_UNARCHIVE_LOCKED_ATTEMPT =
"This note is locked. If you'd like to archive it, unlock it, and try again.";
export const STRING_DELETE_LOCKED_ATTEMPT =
"This note is locked. If you'd like to delete it, unlock it, and try again.";
export const STRING_EDIT_LOCKED_ATTEMPT =
"This note is locked. If you'd like to edit its options, unlock it, and try again.";
export function StringDeleteNote(title: string, permanently: boolean) {
return permanently
? `Are you sure you want to permanently delete ${title}?`
Expand Down
15 changes: 13 additions & 2 deletions app/assets/javascripts/views/editor/editor_view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
STRING_ELLIPSES,
STRING_DELETE_PLACEHOLDER_ATTEMPT,
STRING_DELETE_LOCKED_ATTEMPT,
STRING_EDIT_LOCKED_ATTEMPT,
StringDeleteNote,
StringEmptyTrash,
} from '@/strings';
Expand Down Expand Up @@ -202,9 +203,12 @@ class EditorViewCtrl extends PureViewCtrl<unknown, EditorState> {
if (!this.editorValues.text) {
this.editorValues.text = note.text;
}
if (note.lastSyncBegan) {
if (note.lastSyncBegan || note.dirty) {
if (note.lastSyncEnd) {
if (note.lastSyncBegan!.getTime() > note.lastSyncEnd!.getTime()) {
if (
note.dirty ||
note.lastSyncBegan!.getTime() > note.lastSyncEnd!.getTime()
) {
this.showSavingStatus();
} else if (
note.lastSyncEnd!.getTime() > note.lastSyncBegan!.getTime()
Expand Down Expand Up @@ -305,6 +309,9 @@ class EditorViewCtrl extends PureViewCtrl<unknown, EditorState> {
this.reloadPreferences();
this.reloadStackComponents();
this.reloadNoteTagsComponent();
if (note.dirty) {
this.showSavingStatus();
}
if (note.safeText().length === 0 && !showProtectedWarning) {
this.focusTitle();
}
Expand Down Expand Up @@ -412,6 +419,10 @@ class EditorViewCtrl extends PureViewCtrl<unknown, EditorState> {
if (this.appState.getActiveEditor()?.isTemplateNote) {
await this.appState.getActiveEditor().insertTemplatedNote();
}
if (this.note.locked) {
this.application.alertService.alert(STRING_EDIT_LOCKED_ATTEMPT);
return;
}
if (!component) {
if (!this.note.prefersPlainEditor) {
await this.application.changeItem(this.note.uuid, (mutator) => {
Expand Down

0 comments on commit b93a35f

Please sign in to comment.