Merge pull request #715 from outline/issue-draft-save

Fixes initial draft save issue
This commit is contained in:
Tom Moor
2018-07-08 15:01:06 -05:00
committed by GitHub
3 changed files with 29 additions and 28 deletions

View File

@@ -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 {

View File

@@ -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;

View File

@@ -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);