From 6b01266b1ff7302dba6b941ce5c45a224109bd1e Mon Sep 17 00:00:00 2001 From: Kevin Ansfield Date: Fri, 15 Mar 2019 16:18:53 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fixed=20unnecessary=20"Are=20you?= =?UTF-8?q?=20sure=20you=20want=20to=20leave=3F"=20modals?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit no issue - if a post was saved before the body content was edited you would get stuck with an "Are you sure you want to leave?" modal even though you had already saved - the editor saw the post as being in a dirty state because the `mobiledoc` and `scratch` value were null but after saving the `mobiledoc` value was set to an blank mobiledoc object as returned by the API - updated the `post` model save method to reset the `scratch` value if the returned `mobiledoc` no longer matches --- app/models/post.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/app/models/post.js b/app/models/post.js index 72273826d9..3c1992b302 100644 --- a/app/models/post.js +++ b/app/models/post.js @@ -190,6 +190,19 @@ export default Model.extend(Comparable, ValidationEngine, { } }), + save() { + // ensure that our scratch value used in the editor is kept in sync with + // what we get back from the API after saving - avoids issues which cause + // the editor to see a saved post as dirty and show a "are you sure" modal + return this._super(...arguments).then(() => { + if (JSON.stringify(this.mobiledoc) !== JSON.stringify(this.scratch)) { + this.set('scratch', this.mobiledoc); + } + + return this; + }); + }, + _getPublishedAtBlogTZ() { let publishedAtUTC = this.publishedAtUTC; let publishedAtBlogDate = this.publishedAtBlogDate;