From 94e63b6171133f48ad80c6330e1048dcefc030ee Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Mon, 7 May 2018 22:53:13 -0700 Subject: [PATCH] Account for draft being published. Need to reload the collection still in this scenario --- app/models/Collection.js | 3 +++ app/models/Document.js | 11 ++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/app/models/Collection.js b/app/models/Collection.js index 409909d0..5051ac69 100644 --- a/app/models/Collection.js +++ b/app/models/Collection.js @@ -156,6 +156,9 @@ class Collection extends BaseModel { } } ); + this.on('documents.publish', (data: { collectionId: string }) => { + if (data.collectionId === this.id) this.fetch(); + }); this.on('documents.move', (data: { collectionId: string }) => { if (data.collectionId === this.id) this.fetch(); }); diff --git a/app/models/Document.js b/app/models/Document.js index 975b6458..aa317dc3 100644 --- a/app/models/Document.js +++ b/app/models/Document.js @@ -172,6 +172,8 @@ class Document extends BaseModel { @action save = async (options: SaveOptions) => { if (this.isSaving) return this; + + const wasDraft = !this.publishedAt; this.isSaving = true; try { @@ -208,8 +210,15 @@ class Document extends BaseModel { document: this, collectionId: this.collection.id, }); + + if (wasDraft && this.publishedAt) { + this.emit('documents.publish', { + id: this.id, + collectionId: this.collection.id, + }); + } } catch (e) { - this.errors.add('Document failed saving'); + this.errors.add('Document failed to save'); } finally { this.isSaving = false; }