diff --git a/src/index.js b/src/index.js
index fc1210c03..4f63fe5cd 100644
--- a/src/index.js
+++ b/src/index.js
@@ -42,6 +42,7 @@ render((
+
diff --git a/src/scenes/DocumentEdit/DocumentEdit.js b/src/scenes/DocumentEdit/DocumentEdit.js
index cd96c707d..91801196c 100644
--- a/src/scenes/DocumentEdit/DocumentEdit.js
+++ b/src/scenes/DocumentEdit/DocumentEdit.js
@@ -20,9 +20,17 @@ const cx = classNames.bind(styles);
@observer
class DocumentEdit extends Component {
componentDidMount = () => {
- store.documentId = this.props.params.id;
- store.fetchDocument();
+ // This is a bit hacky, should find a better way
+ if (this.props.route.newDocument) {
+ store.atlasId = this.props.params.id;
+ store.newDocument = true;
+ } else {
+ store.documentId = this.props.params.id;
+ store.newDocument = false;
+ store.fetchDocument();
+ }
+ // Load editor async
EditorLoader()
.then(({ Editor }) => {
this.setState({ Editor });
@@ -34,7 +42,11 @@ class DocumentEdit extends Component {
// alert("Please add a title before saving (hint: Write a markdown header)");
// return
// }
- store.updateDocument();
+ if (store.newDocument) {
+ store.saveDocument();
+ } else {
+ store.updateDocument();
+ }
}
state = {
diff --git a/src/scenes/DocumentEdit/DocumentEditStore.js b/src/scenes/DocumentEdit/DocumentEditStore.js
index 8b439e7d9..6a4bd055c 100644
--- a/src/scenes/DocumentEdit/DocumentEditStore.js
+++ b/src/scenes/DocumentEdit/DocumentEditStore.js
@@ -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;
diff --git a/src/scenes/Editor/Editor.js b/src/scenes/Editor/Editor.js
deleted file mode 100644
index e1996d288..000000000
--- a/src/scenes/Editor/Editor.js
+++ /dev/null
@@ -1,101 +0,0 @@
-import React, { Component } from 'react';
-import { connect } from 'react-redux';
-import { bindActionCreators } from 'redux';
-
-// import {
-// resetEditor,
-// updateText,
-// replaceText,
-// } from 'actions/EditorActions';
-// import {
-// saveDocumentAsync,
-// } from 'actions/DocumentActions';
-
-import Layout, { Title, HeaderAction } from 'components/Layout';
-import Flex from 'components/Flex';
-import MarkdownEditor from 'components/MarkdownEditor';
-import AtlasPreviewLoading from 'components/AtlasPreviewLoading';
-import CenteredContent from 'components/CenteredContent';
-
-import SaveAction from './components/SaveAction';
-import MoreAction from './components/MoreAction';
-
-class Editor extends Component {
- static propTypes = {
- updateText: React.PropTypes.func.isRequired,
- replaceText: React.PropTypes.func.isRequired,
- saveDocumentAsync: React.PropTypes.func.isRequired,
- text: React.PropTypes.string,
- title: React.PropTypes.string,
- }
-
- componentDidMount = () => {
- const atlasId = this.props.routeParams.id;
- this.setState({
- atlasId: atlasId,
- });
- }
-
- onSave = () => {
- if (this.props.title.length === 0) {
- alert("Please add a title before saving (hint: Write a markdown header)");
- return
- }
-
- this.props.saveDocumentAsync(
- this.state.atlasId,
- null,
- this.props.title,
- this.props.text,
- )
- }
-
- render() {
- let title = (
-
- { this.props.title }
-
- );
-
- return (
-
-
-
- )}
- title={ title }
- fixed={ true }
- loading={ this.props.isSaving }
- >
-
-
- );
- }
-}
-
-// const mapStateToProps = (state) => {
-// return {
-// text: state.editor.text,
-// title: state.editor.title,
-// isSaving: state.document.isSaving,
-// };
-// };
-
-// const mapDispatchToProps = (dispatch) => {
-// return bindActionCreators({
-// resetEditor,
-// updateText,
-// replaceText,
-// saveDocumentAsync,
-// }, dispatch)
-// };
-
-export default Editor;
diff --git a/src/scenes/Editor/components/MoreAction.js b/src/scenes/Editor/components/MoreAction.js
deleted file mode 100644
index 0e3a1ad01..000000000
--- a/src/scenes/Editor/components/MoreAction.js
+++ /dev/null
@@ -1,12 +0,0 @@
-import React from 'react';
-import { Arrow } from 'rebass';
-
-const MoreAction = (props) => {
- return (
-
- );
-};
-
-export default MoreAction;
\ No newline at end of file
diff --git a/src/scenes/Editor/components/SaveAction.js b/src/scenes/Editor/components/SaveAction.js
deleted file mode 100644
index cba36ddbc..000000000
--- a/src/scenes/Editor/components/SaveAction.js
+++ /dev/null
@@ -1,23 +0,0 @@
-import React from 'react';
-import { Arrow } from 'rebass';
-
-class SaveAction extends React.Component {
- propTypes = {
- onClick: React.PropTypes.func.isRequired,
- }
-
- onClick = (event) => {
- event.preventDefault();
- this.props.onClick();
- }
-
- render() {
- return (
-
- );
- }
-};
-
-export default SaveAction;
\ No newline at end of file
diff --git a/src/scenes/Editor/index.js b/src/scenes/Editor/index.js
deleted file mode 100644
index 5e0bb9a79..000000000
--- a/src/scenes/Editor/index.js
+++ /dev/null
@@ -1,2 +0,0 @@
-import Editor from './Editor';
-export default Editor;