Account for draft being published. Need to reload the collection still in this scenario
This commit is contained in:
@ -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();
|
||||
});
|
||||
|
@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user