/*
  Body
*/

var React = require('react');
var $ = require('jquery');
var CodeMirror = require('./CodeMirror');
var Analysis = require('./Analysis');

var Body = React.createClass({
  getInitialState: function() {
    return {
      data: [],
    };
  },

  getCode: function(newCode) {
    $.ajax({
      type: 'POST',
      url: '/parse/integers',
      dataType: 'json',
      contentType: 'application/json',
      data: JSON.stringify({data: newCode}),
      success: function(data) {
        console.log('Incoming evaluation for ' + data.name);
        var coords = JSON.parse(data.coords);
        var equation = data.eq;

        console.log(equation);
        console.log(coords);

        this.setState({data: coords});
      }.bind(this),
      error: function(err) {
        console.error('Ooop! You have a ' + err.status + ' error.');
      }.bind(this)
    });
  },

  render: function() {
    var style = {
      content: {
        display: 'flex',
        flexDirection: 'column',
        height: '90vh'
      },
      intro: {
        width: '100%'
      }
    };

    return (
      <div className="main-content" style={style.content}>
        <p id="intro-message" style={style.intro}>{ this.props.intro }</p>
        <CodeMirror getCode={this.getCode} />
        { (this.state.data.length) ? <Analysis data={this.state.data} /> : <span /> }
      </div>
    )
  }
});

module.exports = Body;

@@ -234,16 +234,39 @@
  data: %5B
+%7Bx_axis: 10, y_axis: 0%7D
 %5D,%0A    %7D
@@ -737,22 +737,46 @@
 (%7Bdata: 
+this.state.data.concat(
 coords
+)
 %7D);%0A    

resolve merge conflicts and fix data fetch