Account for draft being published. Need to reload the collection still in this scenario

This commit is contained in:
Tom Moor
2018-05-07 22:53:13 -07:00
parent ba0a7b7f4a
commit 94e63b6171
2 changed files with 13 additions and 1 deletions

View File

@ -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 }) => { this.on('documents.move', (data: { collectionId: string }) => {
if (data.collectionId === this.id) this.fetch(); if (data.collectionId === this.id) this.fetch();
}); });

View File

@ -172,6 +172,8 @@ class Document extends BaseModel {
@action @action
save = async (options: SaveOptions) => { save = async (options: SaveOptions) => {
if (this.isSaving) return this; if (this.isSaving) return this;
const wasDraft = !this.publishedAt;
this.isSaving = true; this.isSaving = true;
try { try {
@ -208,8 +210,15 @@ class Document extends BaseModel {
document: this, document: this,
collectionId: this.collection.id, collectionId: this.collection.id,
}); });
if (wasDraft && this.publishedAt) {
this.emit('documents.publish', {
id: this.id,
collectionId: this.collection.id,
});
}
} catch (e) { } catch (e) {
this.errors.add('Document failed saving'); this.errors.add('Document failed to save');
} finally { } finally {
this.isSaving = false; this.isSaving = false;
} }