From 1dc28832ccd47f06ef2c14b7525a03f82f6c5a2d Mon Sep 17 00:00:00 2001 From: Baptiste Grob <60621355+baptiste-grob@users.noreply.github.com> Date: Wed, 29 Jul 2020 13:12:50 +0200 Subject: [PATCH] fix: debounce note status updates properly --- .../javascripts/views/editor/editor_view.ts | 28 ++++++++----------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/app/assets/javascripts/views/editor/editor_view.ts b/app/assets/javascripts/views/editor/editor_view.ts index 65156a4cc..ae49f057e 100644 --- a/app/assets/javascripts/views/editor/editor_view.ts +++ b/app/assets/javascripts/views/editor/editor_view.ts @@ -511,9 +511,9 @@ class EditorViewCtrl extends PureViewCtrl<{}, EditorState> { }, syncDebouceMs); } - showSavingStatus() { + showSavingStatus() { this.setStatus( - { message: "Saving..." }, + { message: "Saving…" }, false ); } @@ -542,27 +542,21 @@ class EditorViewCtrl extends PureViewCtrl<{}, EditorState> { this.setStatus(error); } - setStatus(status: { message: string, date?: Date }, wait = true) { - let waitForMs; - if (!this.state.noteStatus || !this.state.noteStatus!.date) { - waitForMs = 0; - } else { - waitForMs = MINIMUM_STATUS_DURATION - ( - new Date().getTime() - this.state.noteStatus!.date!.getTime() - ); - } - if (!wait || waitForMs < 0) { - waitForMs = 0; - } + setStatus(status: { message: string }, wait = true) { if (this.statusTimeout) { this.$timeout.cancel(this.statusTimeout); } - this.statusTimeout = this.$timeout(() => { - status.date = new Date(); + if (wait) { + this.statusTimeout = this.$timeout(() => { + this.setState({ + noteStatus: status + }) + }, MINIMUM_STATUS_DURATION); + } else { this.setState({ noteStatus: status }); - }, waitForMs); + } } cancelPendingSetStatus() {