const React = require('react'); const _ = require('lodash'); const cx = require('classnames'); const request = require("superagent"); const Markdown = require('naturalcrit/markdown.js'); const Nav = require('naturalcrit/nav/nav.jsx'); const Navbar = require('../../navbar/navbar.jsx'); const EditTitle = require('../../navbar/editTitle.navitem.jsx'); const IssueNavItem = require('../../navbar/issue.navitem.jsx'); const SplitPane = require('naturalcrit/splitPane/splitPane.jsx'); const Editor = require('../../editor/editor.jsx'); const BrewRenderer = require('../../brewRenderer/brewRenderer.jsx'); const KEY = 'homebrewery-new'; const NewPage = React.createClass({ getInitialState: function() { return { title : '', text: '', isSaving : false, errors : [] }; }, componentDidMount: function() { const storage = localStorage.getItem(KEY); if(storage){ this.setState({ text : storage }) } }, handleSplitMove : function(){ this.refs.editor.update(); }, handleTitleChange : function(title){ this.setState({ title : title }); }, handleTextChange : function(text){ this.setState({ text : text, errors : Markdown.validate(text) }); localStorage.setItem(KEY, text); }, handleSave : function(){ this.setState({ isSaving : true }); request.post('/api') .send({ title : this.state.title, text : this.state.text }) .end((err, res)=>{ if(err){ this.setState({ isSaving : false }); return; } window.onbeforeunload = function(){}; const brew = res.body; localStorage.removeItem(KEY); window.location = '/edit/' + brew.editId; }) }, renderSaveButton : function(){ if(this.state.isSaving){ return save... }else{ return save } }, renderNavbar : function(){ return {this.renderSaveButton()} }, render : function(){ return
{this.renderNavbar()}
} }); module.exports = NewPage;