diff --git a/app/models/Document.js b/app/models/Document.js index 5bd9392f6..aafec02f8 100644 --- a/app/models/Document.js +++ b/app/models/Document.js @@ -190,9 +190,10 @@ class Document extends BaseModel { data.parentDocument = this.parentDocument; } res = await client.post('/documents.create', data); + invariant(res && res.data, 'Data should be available'); + this.emit('documents.create', res.data); } runInAction('Document#save', () => { - invariant(res && res.data, 'Data should be available'); this.updateData(res.data); this.hasPendingChanges = false; }); diff --git a/app/scenes/Document/Document.js b/app/scenes/Document/Document.js index a1722ca1b..1cb0de0c9 100644 --- a/app/scenes/Document/Document.js +++ b/app/scenes/Document/Document.js @@ -211,7 +211,6 @@ class DocumentScene extends Component { const isNew = this.props.newDocument; const isMoving = this.props.match.path === matchDocumentMove; const document = this.document; - const isFetching = !document; const titleText = get(document, 'title', '') || this.props.collections.titleForDocument(this.props.location.pathname); @@ -226,74 +225,71 @@ class DocumentScene extends Component { {isMoving && document && } {titleText && } {(this.isLoading || this.isSaving) && } - {isFetching && ( + {!document ? ( - )} - {!isFetching && - document && ( - - {this.isEditing && ( - - )} - + {this.isEditing && ( + - - {!isNew && - !this.isEditing && } - - {this.isEditing ? ( - - ) : ( - Edit - )} - - {this.isEditing && ( - - Discard - + )} + + + {!isNew && + !this.isEditing && } + + {this.isEditing ? ( + + ) : ( + Edit )} + + {this.isEditing && ( + + Discard + + )} + {!this.isEditing && ( + + + + )} + {!this.isEditing && } + {!this.isEditing && ( - - - + + + )} - {!this.isEditing && } - - {!this.isEditing && ( - - - - )} - - - - )} + + + + )} ); diff --git a/app/stores/DocumentsStore.js b/app/stores/DocumentsStore.js index 6e280d5ff..82a78f029 100644 --- a/app/stores/DocumentsStore.js +++ b/app/stores/DocumentsStore.js @@ -203,6 +203,9 @@ class DocumentsStore extends BaseStore { this.on('documents.delete', (data: { id: string }) => { this.remove(data.id); }); + this.on('documents.create', (data: Document) => { + this.add(new Document(data)); + }); autorunAsync('DocumentsStore.persists', () => { if (this.data.size) {