<commit_before>import React from 'react'
import Slider from 'react-slick'
import django from 'django'

function NextArrow (props) {
  const { onClick } = props
  return (
    <button className="slick-next" onClick={onClick} aria-label={django.ngettext('Next answer')}><i className="fa fa-chevron-right" /></button>
  )
}

function PrevArrow (props) {
  const { onClick } = props
  return (
    <button className="slick-prev" onClick={onClick} aria-label={django.ngettext('Previous answer')}><i className="fa fa-chevron-left" /></button>
  )
}

const disabledArrows = (
  <><button className="slick-next disabled" aria-label={django.ngettext('Next answer')}><i className="fa fa-chevron-right" /></button>
    <button className="slick-prev disabled" aria-label={django.ngettext('Previous answer')}><i className="fa fa-chevron-left" /></button>
  </>
)

export default class PollResult extends React.Component {
  constructor (props) {
    super(props)

    const question = this.props.question
    const openOrOtherAnswerId = question.is_open
      ? question.userAnswer
      : question.other_choice_user_answer

    this.state = {
      question: question,
      selectedChoices: question.userChoices,
      showResult: (question.userChoices.length !== 0) || question.isReadOnly,
      alert: null,
      showOtherAnswers: false,
      userAnswerId: openOrOtherAnswerId
    }
  }

  // FIXME - should add animation for poll results but not current priority
  // doBarTransition (node, style) {
  //   if (node && node.style) {
  //     window.requestAnimationFrame(() => Object.assign(node.style, style))
  //   }
  // }

  isUserAnswer (slide) {
    const matchedId = this.state.question.is_open
      ? slide.id === this.state.userAnswerId
      : slide.vote_id === this.state.userAnswerId
    return !!matchedId
  }

  toggleOtherAnswers () {
    this.setState(prevState => ({ showOtherAnswers: !prevState.showOtherAnswers }))
  }

  getOtherAnswerText () {
    let otherAnswerText
    if (this.state.showOtherAnswers) {
      otherAnswerText = <span>{django.gettext('Hide other answers')}</span>
    } else {
      otherAnswerText = <span>{django.gettext('Show other answers')}</span>
    }
    return (
      otherAnswerText
    )
  }

  getHelpTextAnswer () {
    const total = this.state.question.totalVoteCount
    const totalMulti = this.state.question.totalVoteCountMulti
    let helpTextAnswer
    let helpTextAnswerPlural
    if (this.state.question.multiple_choice) {
      if (total === 1 && totalMulti === 1) {
        helpTextAnswerPlural = django.gettext('%s participant gave 1 answer.')
      } else if (total === 1 && totalMulti > 1) {
        helpTextAnswerPlural = django.gettext('%s participant gave %s answers.', total)
      } else {
        helpTextAnswerPlural = django.ngettext('%s participant gave %s answers.', '%s participants gave %s answers.', total)
      }
      helpTextAnswer = helpTextAnswerPlural + django.gettext(' For multiple choice questions the percentages may add up to more than 100%.')
    } else {
      helpTextAnswer = django.ngettext('1 person has answered.', '%s people have answered.', total)
    }
    return django.interpolate(helpTextAnswer, [total, totalMulti])
  }

  getHelpTextOpenAnswer () {
    const total = this.state.question.totalAnswerCount
    let helpTextOpenAnswer
    if (total >= 1) {
      helpTextOpenAnswer = django.ngettext('1 person has answered.', '%s people have answered.', total)
    } else {
      helpTextOpenAnswer = django.gettext('noone has answered this question')
    }
    return django.interpolate(helpTextOpenAnswer, [total])
  }

  render () {
    const max = Math.max.apply(null, this.state.question.choices.map(c => c.count))
    const total = this.state.question.totalVoteCount

    const settings = {
      arrows: true,
      speed: 500,
      slidesToShow: 1,
      slidesToScroll: 1,
      className: 'poll-slider',
      infinite: false,
      centerMode: true,
      centerPadding: '0px',
      prevArrow: <PrevArrow />,
      nextArrow: <NextArrow />
    }

    return (
      <div className="poll">
        <h2>{this.state.question.label}</h2>
        <div className="poll__rows">
          {this.state.question.choices.map((choice, i) => {
            const percent = total === 0 ? 0 : Math.round(choice.count / total * 100)
            const chosen = this.state.question.userChoices.indexOf(choice.id) !== -1
            const highlight = choice.count === max && max > 0
            return !this.state.question.is_open &&
              <div key={choice.id} className="poll-row__container">
                {chosen ? <i className="poll-row__chosen fas fa-check-circle" aria-label={django.gettext('Your choice')} /> : ''}
                <div className="poll-row poll-row--answered">
                  <div className="poll-row__number">{percent}%</div>
                  <div className="poll-row__label">{choice.label}</div>
                  <div
                    className={'poll-row__bar' + (highlight ? ' poll-row__bar--highlight' : '')}
                    style={{ width: percent + '%' }}
                  />
                </div><commit_msg>polls/assets/PollResults: show other in browser language on result page<commit_after>import React from 'react'
import Slider from 'react-slick'
import django from 'django'

function NextArrow (props) {
  const { onClick } = props
  return (
    <button className="slick-next" onClick={onClick} aria-label={django.ngettext('Next answer')}><i className="fa fa-chevron-right" /></button>
  )
}

function PrevArrow (props) {
  const { onClick } = props
  return (
    <button className="slick-prev" onClick={onClick} aria-label={django.ngettext('Previous answer')}><i className="fa fa-chevron-left" /></button>
  )
}

const disabledArrows = (
  <><button className="slick-next disabled" aria-label={django.ngettext('Next answer')}><i className="fa fa-chevron-right" /></button>
    <button className="slick-prev disabled" aria-label={django.ngettext('Previous answer')}><i className="fa fa-chevron-left" /></button>
  </>
)

export default class PollResult extends React.Component {
  constructor (props) {
    super(props)

    const question = this.props.question
    const openOrOtherAnswerId = question.is_open
      ? question.userAnswer
      : question.other_choice_user_answer

    this.state = {
      question: question,
      selectedChoices: question.userChoices,
      showResult: (question.userChoices.length !== 0) || question.isReadOnly,
      alert: null,
      showOtherAnswers: false,
      userAnswerId: openOrOtherAnswerId
    }
  }

  // FIXME - should add animation for poll results but not current priority
  // doBarTransition (node, style) {
  //   if (node && node.style) {
  //     window.requestAnimationFrame(() => Object.assign(node.style, style))
  //   }
  // }

  isUserAnswer (slide) {
    const matchedId = this.state.question.is_open
      ? slide.id === this.state.userAnswerId
      : slide.vote_id === this.state.userAnswerId
    return !!matchedId
  }

  toggleOtherAnswers () {
    this.setState(prevState => ({ showOtherAnswers: !prevState.showOtherAnswers }))
  }

  getOtherAnswerText () {
    let otherAnswerText
    if (this.state.showOtherAnswers) {
      otherAnswerText = <span>{django.gettext('Hide other answers')}</span>
    } else {
      otherAnswerText = <span>{django.gettext('Show other answers')}</span>
    }
    return (
      otherAnswerText
    )
  }

  getHelpTextAnswer () {
    const total = this.state.question.totalVoteCount
    const totalMulti = this.state.question.totalVoteCountMulti
    let helpTextAnswer
    let helpTextAnswerPlural
    if (this.state.question.multiple_choice) {
      if (total === 1 && totalMulti === 1) {
        helpTextAnswerPlural = django.gettext('%s participant gave 1 answer.')
      } else if (total === 1 && totalMulti > 1) {
        helpTextAnswerPlural = django.gettext('%s participant gave %s answers.', total)
      } else {
        helpTextAnswerPlural = django.ngettext('%s participant gave %s answers.', '%s participants gave %s answers.', total)
      }
      helpTextAnswer = helpTextAnswerPlural + django.gettext(' For multiple choice questions the percentages may add up to more than 100%.')
    } else {
      helpTextAnswer = django.ngettext('1 person has answered.', '%s people have answered.', total)
    }
    return django.interpolate(helpTextAnswer, [total, totalMulti])
  }

  getHelpTextOpenAnswer () {
    const total = this.state.question.totalAnswerCount
    let helpTextOpenAnswer
    if (total >= 1) {
      helpTextOpenAnswer = django.ngettext('1 person has answered.', '%s people have answered.', total)
    } else {
      helpTextOpenAnswer = django.gettext('noone has answered this question')
    }
    return django.interpolate(helpTextOpenAnswer, [total])
  }

  render () {
    const max = Math.max.apply(null, this.state.question.choices.map(c => c.count))
    const total = this.state.question.totalVoteCount

    const settings = {
      arrows: true,
      speed: 500,
      slidesToShow: 1,
      slidesToScroll: 1,
      className: 'poll-slider',
      infinite: false,
      centerMode: true,
      centerPadding: '0px',
      prevArrow: <PrevArrow />,
      nextArrow: <NextArrow />
    }

    return (
      <div className="poll">
        <h2>{this.state.question.label}</h2>
        <div className="poll__rows">
          {this.state.question.choices.map((choice, i) => {
            const percent = total === 0 ? 0 : Math.round(choice.count / total * 100)
            const chosen = this.state.question.userChoices.indexOf(choice.id) !== -1
            const highlight = choice.count === max && max > 0
            return !this.state.question.is_open &&
              <div key={choice.id} className="poll-row__container">
                {chosen ? <i className="poll-row__chosen fas fa-check-circle" aria-label={django.gettext('Your choice')} /> : ''}
                <div className="poll-row poll-row--answered">
                  <div className="poll-row__number">{percent}%</div>
                  <div className="poll-row__label">{choice.is_other_choice ? django.gettext('other') : choice.label}</div>
                  <div
                    className={'poll-row__bar' + (highlight ? ' poll-row__bar--highlight' : '')}
                    style={{ width: percent + '%' }}
                  />
                </div>
{'fraction_non_alphanumeric': 0.13197043862174873, 'fraction_numerical': 0.005182839044054132, 'mean_word_length': 2.9011606140022463, 'pattern_counts': {'":': 0, '<': 69, '<?xml version=': 0, '>': 83, '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': '3001980', 'n_tokens_mistral': 3206, 'n_tokens_neox': 3053, 'n_words': 683}