diff --git a/app/models/Document.js b/app/models/Document.js index 65b5c953f..9b240c0bd 100644 --- a/app/models/Document.js +++ b/app/models/Document.js @@ -175,19 +175,12 @@ class Document extends BaseModel { if (this.isSaving) return this; const wasDraft = !this.publishedAt; + const isCreating = !this.id; this.isSaving = true; try { let res; - if (this.id) { - res = await client.post('/documents.update', { - id: this.id, - title: this.title, - text: this.text, - lastRevision: this.revision, - ...options, - }); - } else { + if (isCreating) { const data = { parentDocument: undefined, collection: this.collection.id, @@ -199,25 +192,36 @@ 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); + } else { + res = await client.post('/documents.update', { + id: this.id, + title: this.title, + text: this.text, + lastRevision: this.revision, + ...options, + }); } runInAction('Document#save', () => { invariant(res && res.data, 'Data should be available'); this.updateData(res.data); this.hasPendingChanges = false; - }); - this.emit('documents.update', { - document: this, - collectionId: this.collection.id, - }); + if (isCreating) { + this.emit('documents.create', this); + } - if (wasDraft && this.publishedAt) { - this.emit('documents.publish', { - id: this.id, + this.emit('documents.update', { + document: this, collectionId: this.collection.id, }); - } + + if (wasDraft && this.publishedAt) { + this.emit('documents.publish', { + id: this.id, + collectionId: this.collection.id, + }); + } + }); } catch (e) { this.ui.showToast('Document failed to save'); } finally { diff --git a/app/scenes/Settings/components/SlackButton.js b/app/scenes/Settings/components/SlackButton.js index cffdd5652..259aa5d76 100644 --- a/app/scenes/Settings/components/SlackButton.js +++ b/app/scenes/Settings/components/SlackButton.js @@ -1,21 +1,18 @@ // @flow import * as React from 'react'; import styled from 'styled-components'; -import { inject } from 'mobx-react'; import { slackAuth } from 'shared/utils/routeHelpers'; -import Button from 'components/Button'; import SlackLogo from 'shared/components/SlackLogo'; -import AuthStore from 'stores/AuthStore'; +import Button from 'components/Button'; type Props = { - auth: AuthStore, scopes?: string[], - redirectUri?: string, + redirectUri: string, state: string, label?: string, }; -function SlackButton({ auth, state, label, scopes, redirectUri }: Props) { +function SlackButton({ state, scopes, redirectUri, label }: Props) { const handleClick = () => (window.location.href = slackAuth(state, scopes, redirectUri)); @@ -36,4 +33,4 @@ const SpacedSlackLogo = styled(SlackLogo)` padding-right: 4px; `; -export default inject('auth')(SlackButton); +export default SlackButton; diff --git a/app/stores/DocumentsStore.js b/app/stores/DocumentsStore.js index ca91c62c5..0a33a1c3d 100644 --- a/app/stores/DocumentsStore.js +++ b/app/stores/DocumentsStore.js @@ -217,7 +217,7 @@ class DocumentsStore extends BaseStore { if (res && res.data) { const duped = res.data; - this.emit('documents.create', duped); + this.emit('documents.create', new Document(duped)); this.emit('documents.publish', { id: duped.id, collectionId: duped.collection.id, @@ -255,7 +255,7 @@ class DocumentsStore extends BaseStore { this.remove(data.id); }); this.on('documents.create', (data: Document) => { - this.add(new Document(data)); + this.add(data); }); this.on('documents.duplicate', (data: Document) => { this.duplicate(data);