From 27ec6f9b997bae780d3979c8996b866c4daca2e5 Mon Sep 17 00:00:00 2001 From: Baptiste Grob <60621355+baptiste-grob@users.noreply.github.com> Date: Fri, 14 Aug 2020 15:23:53 +0200 Subject: [PATCH] fix: always create a template note --- app/assets/javascripts/ui_models/editor.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/ui_models/editor.ts b/app/assets/javascripts/ui_models/editor.ts index ae3f2b6908b..067b8b7ce38 100644 --- a/app/assets/javascripts/ui_models/editor.ts +++ b/app/assets/javascripts/ui_models/editor.ts @@ -7,7 +7,7 @@ export class Editor { private application: WebApplication private _onNoteChange?: () => void private _onNoteValueChange?: (note: SNNote, source?: PayloadSource) => void - private removeStreamObserver: () => void + private removeStreamObserver?: () => void public isTemplateNote = false constructor( @@ -18,10 +18,15 @@ export class Editor { this.application = application; if (noteUuid) { this.note = application.findItem(noteUuid) as SNNote; + this.streamItems(); } else { - this.reset(noteTitle); + this.reset(noteTitle) + .then(() => this.streamItems()) + .catch(console.error); } + } + private streamItems() { this.removeStreamObserver = this.application.streamItems( ContentType.Note, async (items, source) => { @@ -31,7 +36,7 @@ export class Editor { } deinit() { - this.removeStreamObserver(); + this.removeStreamObserver?.(); (this.removeStreamObserver as any) = undefined; this._onNoteChange = undefined; (this.application as any) = undefined;