<commit_before>'use strict'
var Form = require('./Form');
var Deck = require('./Deck');
var Loading = require('../Loading');
var Error = require('../Error');
var History = require('history');

module.exports = React.createClass({
  displayName: 'Creator',

  componentDidMount: function() {
    console.log()

    var id = this.getQueryParam("id");
    this.buildDeck(id);
  },

  getInitialState: function() {
    return {
      deck: { cards: [] },
      loading: false,
      error: false
     };
  },

  getParams: function() {
    return { sets: this.refs.form.state.selectedSets };
  },

  getQueryParam: function(field) {
    var href = window.location.href;
    var reg = new RegExp( '[?&]' + field + '=([^&#]*)', 'i' );
    var string = reg.exec(href);
    return string ? string[1] : null;
  },

  setLoading: function() {
    this.setState({error: false, loading: true});
  },

  handleError: function(err) {
    console.error(err);
    this.setState({error: true, loading: false});
  },

  buildDeck: function(id) {
    this.setLoading();
    if(id) {
      this.getDeckByID(id);
    } else {
      this.getNewDeck();
    }
  },

  getDeckByID: function(id) {
    $.getJSON('/deck/' + id).success(function(data) {
      this.setState({deck: data, loading: false});
      document.title = "Dom Bot | " + this.state.deck.id;
    }.bind(this))
    .error(function(err) {
      this.handleError(err);
    }.bind(this));
  },

  getNewDeck: function() {
    var params = JSON.stringify(this.getParams());
    $.post('/deck', params).success(function(data) {
      data = JSON.parse(data);
      this.setState({deck: data, loading: false});
    }.bind(this))
    .error(function(err) {
      this.handleError(err);
    }.bind(this));

    this.updateHistory();
  },

  updateHistory: function() {
    var windowHistory = History.createHistory()
    windowHistory.pushState(this.state, '?id=' + this.state.deck.id);
    document.title = "Dom Bot | " + this.state.deck.id;
  },

  render: function() {
    return(
      <div>
        <Form ref="form"/>
        { this.state.loading ? <Loading /> :<Deck deck={this.state.deck} />}
        { this.state.error ? <Error /> : null }
      </div>
    );
  }
})<commit_msg>Quick fix<commit_after>'use strict'
var Form = require('./Form');
var Deck = require('./Deck');
var Loading = require('../Loading');
var Error = require('../Error');
var History = require('history');

module.exports = React.createClass({
  displayName: 'Creator',

  componentDidMount: function() {
    console.log()

    var id = this.getQueryParam("id");
    this.buildDeck(id);
  },

  getInitialState: function() {
    return {
      deck: { cards: [] },
      loading: false,
      error: false
     };
  },

  getParams: function() {
    return { sets: this.refs.form.state.selectedSets };
  },

  getQueryParam: function(field) {
    var href = window.location.href;
    var reg = new RegExp( '[?&]' + field + '=([^&#]*)', 'i' );
    var string = reg.exec(href);
    return string ? string[1] : null;
  },

  setLoading: function() {
    this.setState({error: false, loading: true});
  },

  handleError: function(err) {
    console.error(err);
    this.setState({error: true, loading: false});
  },

  buildDeck: function(id) {
    this.setLoading();
    if(id) {
      this.getDeckByID(id);
    } else {
      this.getNewDeck();
    }
  },

  getDeckByID: function(id) {
    $.getJSON('/deck/' + id).success(function(data) {
      this.setState({deck: data, loading: false});
      document.title = "Dom Bot | " + this.state.deck.id;
    }.bind(this))
    .error(function(err) {
      this.handleError(err);
    }.bind(this));
  },

  getNewDeck: function() {
    var params = JSON.stringify(this.getParams());
    $.post('/deck', params).success(function(data) {
      data = JSON.parse(data);
      this.setState({deck: data, loading: false});
    }.bind(this))
    .error(function(err) {
      this.handleError(err);
    }.bind(this));

    this.updateHistory();
  },

  updateHistory: function() {
    var windowHistory = History.createHistory()
    if(this.state.deck.id) {
      windowHistory.pushState(this.state, '?id=' + this.state.deck.id);
      document.title = "Dom Bot | " + this.state.deck.id;
    }
  },

  render: function() {
    return(
      <div>
        <Form ref="form"/>
        { this.state.loading ? <Loading /> :<Deck deck={this.state.deck} />}
        { this.state.error ? <Error /> : null }
      </div>
    );
  }
})
{'fraction_non_alphanumeric': 0.18748603351955306, 'fraction_numerical': 0.000446927374301676, 'mean_word_length': 2.7804054054054053, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4312893', 'n_tokens_mistral': 1516, 'n_tokens_neox': 1481, 'n_words': 282}