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