Implemented new document creation

This commit is contained in:
Jori Lallo
2016-06-05 19:21:28 -07:00
parent 9c0700369d
commit 984140c3ca
7 changed files with 39 additions and 143 deletions

View File

@@ -16,8 +16,10 @@ const parseHeader = (text) => {
const documentEditStore = new class DocumentEditStore {
@observable documentId = null;
@observable title = 'title';
@observable text = 'default state';
@observable atlasId = null;
@observable title = 'Lets start with a title';
@observable text = '# Lets start with a title\n\nAnd continue from there...';
@observable newDocument;
@observable preview;
@observable isFetching;
@@ -41,6 +43,25 @@ const documentEditStore = new class DocumentEditStore {
this.isFetching = false;
}
@action saveDocument = async (nextPath) => {
if (this.isSaving) return;
this.isSaving = true;
try {
const data = await client.post('/documents.create', {
atlas: this.atlasId,
title: this.title,
text: this.text,
})
const { id } = data.data;
browserHistory.push(`/documents/${id}`);
} catch (e) {
console.error("Something went wrong");
}
this.isSaving = false;
}
@action updateDocument = async (nextPath) => {
if (this.isSaving) return;