<commit_before>import ReactDOM from 'react-dom';
import DocumentTitle from 'react-document-title';

'use strict';

var React = require('react');
var Paper = require('material-ui/lib/paper');
var TextField = require('material-ui/lib/text-field');
var Checkbox = require('material-ui/lib/checkbox');
var RaisedButton = require('material-ui/lib/raised-button');
var injectTapEventPlugin = require('react-tap-event-plugin');
var Poll = require('react-1poll');

// Needed for onTouchTap
// Can go away when react 1.0 release, cf https://github.com/zilverline/react-tap-event-plugin
injectTapEventPlugin();

class CreateForm extends React.Component {

  constructor(props) {
    super(props);
    this.state = {
      options: this.props.defaultItems,
      entryToggle: true,
      disabled: false
    };
    this._onNewOption = this._onNewOption.bind(this);
    this._onToggleEntry = this._onToggleEntry.bind(this);
    this._submitNewPoll = this._submitNewPoll.bind(this);
  }

  shouldComponentUpdate(nextProps, nextState) {
    return nextProps != this.props || nextState != this.state;
  }

  componentDidMount() {
    this.refs.title.focus();
  }

  componentDidUpdate() {
    this.props.onUpdate && this.props.onUpdate.call(this, arguments);
  }

  render() {
    return (
    <DocumentTitle title='Create a new 1poll'>
      <form action="#">
        <div className="row">
          <div className="user-signup__intro">
            <TextField
              ref='title'
              autoFocus
              disabled={this.state.disabled}
              hintText="Enter your poll question"
              hintStyle={{ color: '#999' }}
              inputStyle={{ textAlign: 'center', color: 'white' }}
              underlineStyle={{ borderColor: 'transparent' }}
              underlineFocusStyle={{ borderColor: '#999' }}
              style={{ fontSize: '22px', width: '100%' }}
            />
            {/*
            <TextField
              ref='subtitle'
              disabled={this.state.disabled}
              hintText='Enter a description / call to action (optional)'
              hintStyle={{ color: '#999' }}
              inputStyle={{ textAlign: 'center', color: 'white' }}
              underlineStyle={{ borderColor: 'transparent' }}
              underlineFocusStyle={{ borderColor: '#999' }}
              style={{ fontSize: '14px', width: '100%' }}
            />
            */}
            <Checkbox
              name='entryToggle'
              label='Allow voters to enter their own options'
              checked={this.state.entryToggle}
              onCheck={this._onToggleEntry}
              labelStyle={{ color: '#999', fontFamily: 'Roboto, sans-serif' }}
              style={{ marginTop: '20px', marginBottom: '20px' }}
            />
          </div>
        </div>
        <div className="row">
          <div className='react-poll-form'>
            <Paper style={{ padding: '16px', paddingTop: '1px', color: '#333' }}>
              <Poll
                ref='poll'
                disabled={this.state.disabled}
                options={this.state.options}
                allowNewEntries={true}
                onNewOption={this._onNewOption}
                labelStyle={{ color: 'auto' }}
              />
              <RaisedButton
                disabled={this.state.disabled || this.state.options.length == 0}
                label='Publish'
                primary={true}
                backgroundColor='#00a651'
                style={{
                  display: 'block', // to fill the parent div's width
                  marginTop: '16px'
                }}
                onTouchTap={this._submitNewPoll}
              />
            </Paper>
          </div>
        </div>
      </form>
    </DocumentTitle>
    );
  }

  _onNewOption(newOption) {
    if (newOption.name.trim().length > 0) {
      this.setState({
        options: this.state.options.concat([ newOption ])
      });
    }
  }

  _onToggleEntry() {
    this.setState({
      entryToggle: !this.state.entryToggle
    });
  }

  // store new poll in db
  _submitNewPoll() {
    // UI action feedback
    this.setState({ disabled: true });
    this.props.setLoading(true);<commit_msg>move "allow voters to add options" to bottom<commit_after>import ReactDOM from 'react-dom';
import DocumentTitle from 'react-document-title';

'use strict';

var React = require('react');
var Paper = require('material-ui/lib/paper');
var TextField = require('material-ui/lib/text-field');
var Checkbox = require('material-ui/lib/checkbox');
var RaisedButton = require('material-ui/lib/raised-button');
var injectTapEventPlugin = require('react-tap-event-plugin');
var Poll = require('react-1poll');

// Needed for onTouchTap
// Can go away when react 1.0 release, cf https://github.com/zilverline/react-tap-event-plugin
injectTapEventPlugin();

class CreateForm extends React.Component {

  constructor(props) {
    super(props);
    this.state = {
      options: this.props.defaultItems,
      entryToggle: true,
      disabled: false
    };
    this._onNewOption = this._onNewOption.bind(this);
    this._onToggleEntry = this._onToggleEntry.bind(this);
    this._submitNewPoll = this._submitNewPoll.bind(this);
  }

  shouldComponentUpdate(nextProps, nextState) {
    return nextProps != this.props || nextState != this.state;
  }

  componentDidMount() {
    this.refs.title.focus();
  }

  componentDidUpdate() {
    this.props.onUpdate && this.props.onUpdate.call(this, arguments);
  }

  render() {
    return (
    <DocumentTitle title='Create a new 1poll'>
      <form action="#">
        <div className="row">
          <div className="user-signup__intro">
            <TextField
              ref='title'
              autoFocus
              disabled={this.state.disabled}
              hintText="Enter your poll question"
              hintStyle={{ color: '#999' }}
              inputStyle={{ textAlign: 'center', color: 'white' }}
              underlineStyle={{ borderColor: 'transparent' }}
              underlineFocusStyle={{ borderColor: '#999' }}
              style={{ fontSize: '22px', width: '100%', marginBottom: '20px' }}
            />
            {/*
            <TextField
              ref='subtitle'
              disabled={this.state.disabled}
              hintText='Enter a description / call to action (optional)'
              hintStyle={{ color: '#999' }}
              inputStyle={{ textAlign: 'center', color: 'white' }}
              underlineStyle={{ borderColor: 'transparent' }}
              underlineFocusStyle={{ borderColor: '#999' }}
              style={{ fontSize: '14px', width: '100%' }}
            />
            */}
          </div>
        </div>
        <div className="row">
          <div className='react-poll-form'>
            <Paper style={{ padding: '16px', paddingTop: '1px', color: '#333' }}>
              <Poll
                ref='poll'
                disabled={this.state.disabled}
                options={this.state.options}
                allowNewEntries={true}
                onNewOption={this._onNewOption}
                labelStyle={{ color: 'auto' }}
              />
              <RaisedButton
                disabled={this.state.disabled || this.state.options.length == 0}
                label='Publish'
                primary={true}
                backgroundColor='#00a651'
                style={{
                  display: 'block', // to fill the parent div's width
                  marginTop: '16px'
                }}
                onTouchTap={this._submitNewPoll}
              />
            </Paper>
          </div>
          <Checkbox
            name='entryToggle'
            label='Allow voters to add their own options'
            checked={this.state.entryToggle}
            onCheck={this._onToggleEntry}
            labelStyle={{ color: '#999', fontFamily: 'Roboto, sans-serif' }}
            style={{ marginTop: '20px' }}
          />
        </div>
      </form>
    </DocumentTitle>
    );
  }

  _onNewOption(newOption) {
    if (newOption.name.trim().length > 0) {
      this.setState({
        options: this.state.options.concat([ newOption ])
      });
    }
  }

  _onToggleEntry() {
    this.setState({
      entryToggle: !this.state.entryToggle
    });
  }

  // store new poll in db
  _submitNewPoll() {
    // UI action feedback
    this.setState({ disabled: true });
    this.props.setLoading(true);
{'fraction_non_alphanumeric': 0.13670345318618726, 'fraction_numerical': 0.011391954432182272, 'mean_word_length': 1.9823071479122434, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 43, 'https://': 2, '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': '4508572', 'n_tokens_mistral': 2418, 'n_tokens_neox': 2317, 'n_words': 484}