diff --git a/app/models/Document.js b/app/models/Document.js index 5bd9392f6..70488fb26 100644 --- a/app/models/Document.js +++ b/app/models/Document.js @@ -190,6 +190,7 @@ class Document extends BaseModel { data.parentDocument = this.parentDocument; } res = await client.post('/documents.create', data); + if (res && res.data) this.emit('documents.create', res.data); } runInAction('Document#save', () => { invariant(res && res.data, 'Data should be available'); diff --git a/app/scenes/Document/Document.js b/app/scenes/Document/Document.js index dc6efe6db..1cb0de0c9 100644 --- a/app/scenes/Document/Document.js +++ b/app/scenes/Document/Document.js @@ -168,9 +168,12 @@ class DocumentScene extends Component { document = await document.save(); this.isSaving = false; - if (redirect || this.props.newDocument) { + if (redirect) { this.props.history.push(document.url); this.props.ui.setActiveDocument(document); + } else if (this.props.newDocument) { + this.props.history.push(documentEditUrl(document)); + this.props.ui.setActiveDocument(document); } }; @@ -208,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); @@ -223,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) {