<commit_before>import { Router, Route, Link } from 'react-router';
import { createHashHistory } from 'history';

(function(){
  'use strict';
  
  var React = require('react');
  var ReactDOM = require('react-dom');
  var CreateForm = require('./CreateForm.jsx');
  var pollStore = require('./pollStore.js');

  // Needed for React Developer Tools
  window.React = React;

  var DEFAULT_ITEMS = [ /* { name: 'Option 1' } */ ];

  // displays the loading animation if toggle == true
  function setLoading(toggle) {
    document.body.className = (document.body.className || '').replace(/is\-loading/, '');
    if (toggle) {
      document.body.className += ' is-loading';
    }
  }

  // store new poll in db
  function submit(formData) {
    setLoading(true);
    pollStore.save({
      title: formData.title,
      subtitle: formData.subtitle,
      options: formData.options.map((opt) => { return opt.name; })
    }, function(err, result) {
      setLoading(false);
      if (err) {
        alert('Error: ' + JSON.stringify(err));
      } else {
        alert('TODO: display poll + link to share');
      }
    });
  };

  // ___
  // Main logic

  var appDiv = document.getElementById('app');

  function heightTransition() {
    setTimeout(function() {
      appDiv.style.maxHeight = appDiv.childNodes[0].clientHeight + 'px';
    });
    setTimeout(function() {
      appDiv.style.maxHeight = 'none';
    }, 1000);
  }

  var CreatePage = React.createClass({
    render: function() {
      return (
        <CreateForm
          onSubmit={submit}
          onUpdate={heightTransition}
        />
      );
    }
  });

  var PollPage = React.createClass({
    render: function() {
      return (
        <CreateForm
          defaultItems={[{ name: 'coucou' + this.props.params.id }]}
          onSubmit={submit}
          onUpdate={heightTransition}
        />
      );
    }
  });

  var Unknown = React.createClass({
    render: function() {
      return (
        <p>unknown route</p>
      );
    }
  });

  var history = createHashHistory({
    queryKey: false // removes state hashes, cf https://github.com/rackt/react-router/blob/master/docs/guides/basics/Histories.md#what-is-that-_kckuvup-junk-in-the-url
  });

  var router = (
    <Router history={history}>
      <Route path='/' component={CreatePage}/>
      <Route path='/:id' component={PollPage}/>
      <Route path='*' component={Unknown}/>
    </Router>
  );

  ReactDOM.render(router, appDiv);

})();<commit_msg>minor refactoring<commit_after>import React from 'react';
import ReactDOM from 'react-dom';
import { Router, Route, Link } from 'react-router';
import { createHashHistory } from 'history';

import ViewForm from './ViewForm.jsx';
import CreateForm from './CreateForm.jsx';

import pollStore from './pollStore.js';


(function(){
  'use strict';
  
  // Needed for React Developer Tools
  window.React = React;

  var appDiv = document.getElementById('app');

  // animates the height of the options list
  function heightTransition() {
    setTimeout(function() {
      appDiv.style.maxHeight = appDiv.childNodes[0].clientHeight + 'px';
    });
    setTimeout(function() {
      appDiv.style.maxHeight = 'none';
    }, 1000);
  }

  // displays the loading animation if toggle == true
  function setLoading(toggle) {
    document.body.className = (document.body.className || '').replace(/is\-loading/, '');
    if (toggle) {
      document.body.className += ' is-loading';
    }
  }

  // store new poll in db
  function submitNewPoll(formData) {
    setLoading(true);
    pollStore.save({
      title: formData.title,
      subtitle: formData.subtitle,
      options: formData.options.map((opt) => { return opt.name; })
    }, function(err, result) {
      setLoading(false);
      if (err) {
        alert('Error: ' + JSON.stringify(err));
      } else {
        alert('TODO: display poll + link to share');
      }
    });
  };

  function submitVote() {
    console.log('submitvote', arguments);
  }

  var CreatePage = React.createClass({
    render: function() {
      return (
        <CreateForm
          onSubmit={submitNewPoll}
          onUpdate={heightTransition}
        />
      );
    }
  });

  var PollPage = React.createClass({
    render: function() {
      return (
        <CreateForm
          defaultItems={[{ name: 'coucou' + this.props.params.id }]}
          onSubmit={submit}
          onUpdate={heightTransition}
        />
      );
    }
  });

  var UnknownPage = React.createClass({
    render: function() {
      return (
        <p>unknown route</p>
      );
    }
  });

  var history = createHashHistory({
    queryKey: false // removes state hashes, cf https://github.com/rackt/react-router/blob/master/docs/guides/basics/Histories.md#what-is-that-_kckuvup-junk-in-the-url
  });

  var router = (
    <Router history={history}>
      <Route path='/' component={CreatePage}/>
      <Route path='/:id' component={PollPage}/>
      <Route path='*' component={UnknownPage}/>
    </Router>
  );

  ReactDOM.render(router, appDiv);

})();
{'fraction_non_alphanumeric': 0.1543942992874109, 'fraction_numerical': 0.00217735550277118, 'mean_word_length': 2.5938833570412516, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 23, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4774499', 'n_tokens_mistral': 1579, 'n_tokens_neox': 1543, 'n_words': 323}