Skip to content

Commit

Permalink
fix: editor status after changing note
Browse files Browse the repository at this point in the history
  • Loading branch information
moughxyz committed Apr 24, 2020
1 parent fa831f7 commit dee164f
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 68 deletions.
12 changes: 5 additions & 7 deletions app/assets/javascripts/ui_models/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,21 +75,19 @@ export class Editor {
/**
* Register to be notified when the editor's note changes.
*/
public onNoteChange(onNoteChange: () => void) {
this._onNoteChange = onNoteChange;
public onNoteChange(callback: () => void) {
this._onNoteChange = callback;
if (this.note) {
onNoteChange();
callback();
}
}

/**
* Register to be notified when the editor's note's values change
* (and thus a new object reference is created)
*/
public onNoteValueChange(
onNoteValueChange: (note: SNNote, source?: PayloadSource) => void
) {
this._onNoteValueChange = onNoteValueChange;
public onNoteValueChange(callback: (note: SNNote, source?: PayloadSource) => void) {
this._onNoteValueChange = callback;
}

/**
Expand Down
12 changes: 9 additions & 3 deletions app/assets/javascripts/views/abstract/pure_view_ctrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,10 @@ export class PureViewCtrl {
await this.onAppStart();
} else if (eventName === ApplicationEvent.Launched) {
await this.onAppLaunch();
} else if (eventName === ApplicationEvent.CompletedSync) {
this.onAppSync();
} else if (eventName === ApplicationEvent.CompletedIncrementalSync) {
this.onAppIncrementalSync();
} else if (eventName === ApplicationEvent.CompletedFullSync) {
this.onAppFullSync();
} else if (eventName === ApplicationEvent.KeyStatusChanged) {
this.onAppKeyChange();
}
Expand All @@ -131,7 +133,11 @@ export class PureViewCtrl {
/** Optional override */
}

onAppSync() {
onAppIncrementalSync() {
/** Optional override */
}

onAppFullSync() {
/** Optional override */
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class ApplicationViewCtrl extends PureViewCtrl {
"Syncing..."
);
}
} else if (eventName === ApplicationEvent.CompletedSync) {
} else if (eventName === ApplicationEvent.CompletedFullSync) {
if (!this.completedInitialSync) {
this.syncStatus = this.application!.getStatusService().removeStatus(this.syncStatus);
this.completedInitialSync = true;
Expand Down
19 changes: 15 additions & 4 deletions app/assets/javascripts/views/editor/editor_view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const NOTE_PREVIEW_CHAR_LIMIT = 80;
const MINIMUM_STATUS_DURATION = 400;
const SAVE_TIMEOUT_DEBOUNCE = 350;
const SAVE_TIMEOUT_NO_DEBOUNCE = 100;
const EDITOR_DEBOUNCE = 200;
const EDITOR_DEBOUNCE = 100;

const ElementIds = {
NoteTextEditor: 'note-text-editor',
Expand Down Expand Up @@ -71,6 +71,8 @@ type EditorState = {
syncTakingTooLong: boolean
showExtensions: boolean
showOptionsMenu: boolean
showEditorMenu: boolean
showSessionHistory: boolean
altKeyDown: boolean
spellcheck: boolean
/** Setting to false then true will allow the current editor component-view to be destroyed
Expand Down Expand Up @@ -256,7 +258,7 @@ class EditorViewCtrl extends PureViewCtrl implements EditorViewScope {
onAppEvent(eventName: ApplicationEvent) {
if (eventName === ApplicationEvent.HighLatencySync) {
this.setEditorState({ syncTakingTooLong: true });
} else if (eventName === ApplicationEvent.CompletedSync) {
} else if (eventName === ApplicationEvent.CompletedFullSync) {
this.setEditorState({ syncTakingTooLong: false });
const isInErrorState = this.getState().saveError;
/** if we're still dirty, don't change status, a sync is likely upcoming. */
Expand Down Expand Up @@ -293,22 +295,25 @@ class EditorViewCtrl extends PureViewCtrl implements EditorViewScope {
}

async handleEditorNoteChange() {
const note = this.editor.note;
this.cancelPendingSetStatus();
await this.setEditorState({
showExtensions: false,
showOptionsMenu: false,
showEditorMenu: false,
showSessionHistory: false,
altKeyDown: false,
noteStatus: undefined
});
const note = this.editor.note;
this.editorValues.title = note.title;
this.editorValues.text = note.text;
await this.reloadComponentEditorState();
this.reloadTagsString();
this.reloadPreferences();
this.reloadComponentContext();
if (note.safeText().length === 0) {
this.focusTitle();
}
this.reloadComponentContext();
}

async reloadComponentEditorState() {
Expand Down Expand Up @@ -603,6 +608,12 @@ class EditorViewCtrl extends PureViewCtrl implements EditorViewScope {
}, waitForMs);
}

cancelPendingSetStatus() {
if (this.statusTimeout) {
this.$timeout.cancel(this.statusTimeout);
}
}

contentChanged() {
this.saveNote(
false,
Expand Down
2 changes: 1 addition & 1 deletion app/assets/javascripts/views/footer/footer_view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ class FooterViewCtrl extends PureViewCtrl {
this.setState({
outOfSync: false
});
} else if (eventName === ApplicationEvent.CompletedSync) {
} else if (eventName === ApplicationEvent.CompletedFullSync) {
if (!this.didCheckForOffline) {
this.didCheckForOffline = true;
if (this.offline && this.application!.getNoteCount() === 0) {
Expand Down
2 changes: 1 addition & 1 deletion app/assets/javascripts/views/notes/notes_view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ class NotesViewCtrl extends PureViewCtrl {
if (eventName === ApplicationEvent.SignedIn) {
this.appState.closeAllEditors();
this.selectFirstNote();
} else if (eventName === ApplicationEvent.CompletedSync) {
} else if (eventName === ApplicationEvent.CompletedFullSync) {
this.getMostValidNotes().then((notes) => {
if (notes.length === 0) {
this.createPlaceholderNote();
Expand Down
12 changes: 3 additions & 9 deletions app/assets/javascripts/views/tags/tags_view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ class TagsViewCtrl extends PureViewCtrl {
}

/** @override */
onAppSync() {
super.onAppSync();
onAppIncrementalSync() {
super.onAppIncrementalSync();
this.reloadNoteCounts();
}

Expand Down Expand Up @@ -166,12 +166,6 @@ class TagsViewCtrl extends PureViewCtrl {
super.onAppEvent(eventName);
if (eventName === ApplicationEvent.LocalDataIncrementalLoad) {
this.reloadNoteCounts();
} else if (eventName === ApplicationEvent.SyncStatusChanged) {
const syncStatus = this.application.getSyncStatus();
const stats = syncStatus.getStats();
if (stats.downloadCount > 0) {
this.reloadNoteCounts();
}
}
}

Expand All @@ -187,7 +181,7 @@ class TagsViewCtrl extends PureViewCtrl {
for (const tag of allTags) {
if (tag.isSmartTag()) {
/** Other smart tags do not contain counts */
if(tag.isAllTag) {
if (tag.isAllTag) {
const notes = this.application.notesMatchingSmartTag(tag as SNSmartTag)
.filter((note) => {
return !note.archived && !note.trashed;
Expand Down
90 changes: 49 additions & 41 deletions dist/javascripts/app.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/javascripts/app.js.map

Large diffs are not rendered by default.

0 comments on commit dee164f

Please sign in to comment.