<commit_before>var React = require('react')
var ReactDOM = require('react-dom')
var django = require('django')

var Poll = React.createClass({
  getInitialState: function () {
    // FIXME: example data
    return {
      title: 'Getrennte Eltern: Ist das Wechselmodell die beste Lösung für alle?',
      options: [{
        label: 'Ja',
        count: 22434
      }, {
        label: 'Nein',
        count: 40062
      }, {
        label: 'Vielleicht',
        count: 17627
      }],
      own: null,
      active: true,
      showResult: false
    }
  },

  toggleShowResult: function () {
    this.setState({
      showResult: !this.state.showResult
    })
  },

  vote: function (event) {
    event.preventDefault()

    let rawValue = event.target.poll.value
    if (!rawValue) {
      // TODO: show error
    } else {
      let value = parseInt(rawValue)
      // TODO: sent to server
      // TODO: show success/error message
      this.setState({
        showResult: true,
        own: value
      })
    }
  },

  render: function () {
    let counts = this.state.options.map(o => o.count)
    let total = counts.reduce((sum, c) => sum + c, 0)
    let max = Math.max.apply(null, counts)

    return (
      <form onSubmit={this.vote}>
        <h2>{ this.state.title }</h2>

        <div className="poll">
          {
            this.state.options.map((option, i) => {
              let checked = this.state.own === i
              let percent = Math.round(option.count / total * 100)
              let highlight = option.count === max

              if (this.state.showResult || !this.state.active) {
                return (
                  <div className="poll-row" key={i}>
                    <div className={'poll-row__bar' + (highlight ? ' poll-row__bar--highlight' : '')} style={{width: percent + '%'}} />
                    <div className="poll-row__number">{ percent }%</div>
                    <div className="poll-row__label">{ option.label }</div>
                    &nbsp;
                    { checked ? <i className="fa fa-check-circle u-secondary" aria-label={django.gettext('Your choice')} /> : '' }
                  </div>
                )
              } else {
                return (
                  <label className="poll-row" key={i}>
                    <input
                      className="poll-row__radio"
                      type="radio"
                      name="poll"
                      value={i}
                      defaultChecked={checked} />
                    &nbsp;
                    { option.label }
                  </label><commit_msg>rename own to ownVote<commit_after>var React = require('react')
var ReactDOM = require('react-dom')
var django = require('django')

var Poll = React.createClass({
  getInitialState: function () {
    // FIXME: example data
    return {
      title: 'Getrennte Eltern: Ist das Wechselmodell die beste Lösung für alle?',
      options: [{
        label: 'Ja',
        count: 22434
      }, {
        label: 'Nein',
        count: 40062
      }, {
        label: 'Vielleicht',
        count: 17627
      }],
      ownVote: null,
      active: true,
      showResult: false
    }
  },

  toggleShowResult: function () {
    this.setState({
      showResult: !this.state.showResult
    })
  },

  vote: function (event) {
    event.preventDefault()

    let rawValue = event.target.poll.value
    if (!rawValue) {
      // TODO: show error
    } else {
      let value = parseInt(rawValue)
      // TODO: sent to server
      // TODO: show success/error message
      this.setState({
        showResult: true,
        ownVote: value
      })
    }
  },

  render: function () {
    let counts = this.state.options.map(o => o.count)
    let total = counts.reduce((sum, c) => sum + c, 0)
    let max = Math.max.apply(null, counts)

    return (
      <form onSubmit={this.vote}>
        <h2>{ this.state.title }</h2>

        <div className="poll">
          {
            this.state.options.map((option, i) => {
              let checked = this.state.ownVote === i
              let percent = Math.round(option.count / total * 100)
              let highlight = option.count === max

              if (this.state.showResult || !this.state.active) {
                return (
                  <div className="poll-row" key={i}>
                    <div className={'poll-row__bar' + (highlight ? ' poll-row__bar--highlight' : '')} style={{width: percent + '%'}} />
                    <div className="poll-row__number">{ percent }%</div>
                    <div className="poll-row__label">{ option.label }</div>
                    &nbsp;
                    { checked ? <i className="fa fa-check-circle u-secondary" aria-label={django.gettext('Your choice')} /> : '' }
                  </div>
                )
              } else {
                return (
                  <label className="poll-row" key={i}>
                    <input
                      className="poll-row__radio"
                      type="radio"
                      name="poll"
                      value={i}
                      defaultChecked={checked} />
                    &nbsp;
                    { option.label }
                  </label>
{'fraction_non_alphanumeric': 0.13445378151260504, 'fraction_numerical': 0.008021390374331552, 'mean_word_length': 1.5081417624521072, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 39, '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': '4862908', 'n_tokens_mistral': 1523, 'n_tokens_neox': 1451, 'n_words': 334}