<commit_before>import ReactDOM from 'react-dom'
import React from 'react'
import { find } from 'lodash'

const TasksList = React.createClass({
  render: function() {
    const createItem = function(item) {
      return (
        <tr key={item.id} className={item.current ? 'info' : null}>
          <th>{item.id + 1}</th>
          <th className={item.task === 'Break' ? 'taskCell break' : 'task-cell'}>{item.task}</th>
          <th className="text-right">{item.durationMins}:{item.durationSecs}</th>
        </tr>
      )
    }
    return (
      <div className="list">
        <table className="table table-stripped">
          <thead>
            <tr>
              <th></th>
              <th>Task</th>
              <th className="text-right">Duration</th>
            </tr>
          </thead>
          <tbody>
            {this.props.tasksList.map(createItem)}
          </tbody>
        </table>
      </div>
    )
  },
})

const Timer = React.createClass({
  getInitialState: function() {
    return {
      timeRemainingMins: 25,
      timeRemainingSecs: '00',
      tasksList: [],
      task: '',
      pomosNum: 0,
      breaksNum: 0,
      pomosMins: 0,
      breaksMins: 0,
    }
  },
  onChange: function(e) {
    this.setState({task: e.target.value})
  },
  handleSubmit: function(e) {
    e.preventDefault()
    if (this.state.task === '') {
      return
    }
    const newItemArray = [
      {
        id: this.state.tasksList.length + 1,
        task: 'Break',
        durationMins: 5,
        durationSecs: '00',
        current: false,
        done: false,
        createdOn: Date.now(),
      },
      {
        id: this.state.tasksList.length,
        task: this.state.task,
        durationMins: 25,
        durationSecs: '00',
        current: false,
        done: false,
        createdOn: Date.now(),
      },
    ]
    if (!find(this.state.tasksList, {current: true})) {
      newItemArray[1].current = true
    }
    const nextItems = newItemArray.concat(this.state.tasksList)
    const nextText = ''
    this.setState({
      tasksList: nextItems,
      task: nextText,
    })
    if (this.state.tasksList.length === 0) {
      this.start()
    }
  },
  next: function() {
    const currentTask = find(this.state.tasksList, {current: true})
    if ((currentTask.id + 1) === this.state.tasksList.length) {
      return
    }
    const nextTask = find(this.state.tasksList, {id: currentTask.id + 1})
    currentTask.current = false
    nextTask.current = true
    currentTask.done = true
    nextTask.done = true
    const currentIndex = this.state.tasksList.indexOf(currentTask)
    const nextIndex = this.state.tasksList.indexOf(nextTask)
    const newTasksList = this.state.tasksList
    newTasksList[currentIndex].current = false
    newTasksList[nextIndex].current = true
    this.setState({
      tasksList: newTasksList,
      timeRemainingMins: nextTask.durationMins,
      timeRemainingSecs: nextTask.durationSecs,
    })
    this.updateMetricsNum()
    this.pause()
    this.start()
  },
  updateMetricsNum: function () {
    const newTask = find(this.state.tasksList, {current: true})
    let newPomosNum = this.state.pomosNum
    let newBreaksNum = this.state.breaksNum
    if (newTask.task === 'Break') {
      newPomosNum = this.state.pomosNum + 1
    } else {
      newBreaksNum = this.state.breaksNum + 1
    }
    this.setState({
      pomosNum: newPomosNum,
      breaksNum: newBreaksNum,
    })
  },
  tickMinPomo: function() {
    const newPomosMins = this.state.pomosMins + 1
    this.setState({
      pomosMins: newPomosMins,
    })
  },
  tickMinBreak: function() {
    const newBreakMins = this.state.breaksMins + 1
    this.setState({
      breaksMins: newBreakMins,
    })
  },
  tick: function() {
    let newTimeRemainingMins
    let newTimeRemainingSecs
    if (this.state.timeRemainingSecs > 0) {
      newTimeRemainingMins = this.state.timeRemainingMins
      newTimeRemainingSecs = this.state.timeRemainingSecs -  1
      if (newTimeRemainingSecs < 10) {
        newTimeRemainingSecs = '0' + newTimeRemainingSecs
      }
    } else {
      newTimeRemainingMins = this.state.timeRemainingMins - 1
      if (this.state.timeRemainingSecs === 0 || this.state.timeRemainingSecs === '00') {
        newTimeRemainingSecs = 59
      } else {
        newTimeRemainingSecs = this.state.timeRemainingSecs -  1
      }
    }
    this.setState({
      timeRemainingMins: newTimeRemainingMins,
      timeRemainingSecs: newTimeRemainingSecs,
    })
    this.listenForNorify()
  },
  start: function() {
    this.intervalSec = setInterval(this.tick, 1000)
    const currentTask = find(this.state.tasksList, {current: true})
    if (!currentTask || currentTask.task !== 'Break') {
      this.intervalMin = setInterval(this.tickMinPomo, 1000 * 60)
    } else {
      this.intervalMin = setInterval(this.tickMinBreak, 1000 * 60)
    }
  },
  pause: function() {
    clearInterval(this.intervalSec)
    clearInterval(this.intervalMin)
  },
  resetTasks: function() {
    this.setState(this.getInitialState())
    window.localStorage.setItem('ketchupState', '')
  },
  listenForNorify: function() {
    if (this.state.timeRemainingMins === 0 && this.state.timeRemainingSecs === '00') {
      var audio = new Audio('assets/ding.ogg')
      audio.play()
    }
  },
  componentDidUpdate: function() {<commit_msg>do not start countdown more than once<commit_after>import ReactDOM from 'react-dom'
import React from 'react'
import { find } from 'lodash'

const TasksList = React.createClass({
  render: function() {
    const createItem = function(item) {
      return (
        <tr key={item.id} className={item.current ? 'info' : null}>
          <th>{item.id + 1}</th>
          <th className={item.task === 'Break' ? 'taskCell break' : 'task-cell'}>{item.task}</th>
          <th className="text-right">{item.durationMins}:{item.durationSecs}</th>
        </tr>
      )
    }
    return (
      <div className="list">
        <table className="table table-stripped">
          <thead>
            <tr>
              <th></th>
              <th>Task</th>
              <th className="text-right">Duration</th>
            </tr>
          </thead>
          <tbody>
            {this.props.tasksList.map(createItem)}
          </tbody>
        </table>
      </div>
    )
  },
})

const Timer = React.createClass({
  getInitialState: function() {
    return {
      timeRemainingMins: 25,
      timeRemainingSecs: '00',
      tasksList: [],
      task: '',
      pomosNum: 0,
      breaksNum: 0,
      pomosMins: 0,
      breaksMins: 0,
    }
  },
  onChange: function(e) {
    this.setState({task: e.target.value})
  },
  handleSubmit: function(e) {
    e.preventDefault()
    if (this.state.task === '') {
      return
    }
    const newItemArray = [
      {
        id: this.state.tasksList.length + 1,
        task: 'Break',
        durationMins: 5,
        durationSecs: '00',
        current: false,
        done: false,
        createdOn: Date.now(),
      },
      {
        id: this.state.tasksList.length,
        task: this.state.task,
        durationMins: 25,
        durationSecs: '00',
        current: false,
        done: false,
        createdOn: Date.now(),
      },
    ]
    if (!find(this.state.tasksList, {current: true})) {
      newItemArray[1].current = true
    }
    const nextItems = newItemArray.concat(this.state.tasksList)
    const nextText = ''
    this.setState({
      tasksList: nextItems,
      task: nextText,
    })
    if (this.state.tasksList.length === 0) {
      this.start()
    }
  },
  next: function() {
    const currentTask = find(this.state.tasksList, {current: true})
    if ((currentTask.id + 1) === this.state.tasksList.length) {
      return
    }
    const nextTask = find(this.state.tasksList, {id: currentTask.id + 1})
    currentTask.current = false
    nextTask.current = true
    currentTask.done = true
    nextTask.done = true
    const currentIndex = this.state.tasksList.indexOf(currentTask)
    const nextIndex = this.state.tasksList.indexOf(nextTask)
    const newTasksList = this.state.tasksList
    newTasksList[currentIndex].current = false
    newTasksList[nextIndex].current = true
    this.setState({
      tasksList: newTasksList,
      timeRemainingMins: nextTask.durationMins,
      timeRemainingSecs: nextTask.durationSecs,
    })
    this.updateMetricsNum()
    this.pause()
    this.start()
  },
  updateMetricsNum: function () {
    const newTask = find(this.state.tasksList, {current: true})
    let newPomosNum = this.state.pomosNum
    let newBreaksNum = this.state.breaksNum
    if (newTask.task === 'Break') {
      newPomosNum = this.state.pomosNum + 1
    } else {
      newBreaksNum = this.state.breaksNum + 1
    }
    this.setState({
      pomosNum: newPomosNum,
      breaksNum: newBreaksNum,
    })
  },
  tickMinPomo: function() {
    const newPomosMins = this.state.pomosMins + 1
    this.setState({
      pomosMins: newPomosMins,
    })
  },
  tickMinBreak: function() {
    const newBreakMins = this.state.breaksMins + 1
    this.setState({
      breaksMins: newBreakMins,
    })
  },
  tick: function() {
    let newTimeRemainingMins
    let newTimeRemainingSecs
    if (this.state.timeRemainingSecs > 0) {
      newTimeRemainingMins = this.state.timeRemainingMins
      newTimeRemainingSecs = this.state.timeRemainingSecs -  1
      if (newTimeRemainingSecs < 10) {
        newTimeRemainingSecs = '0' + newTimeRemainingSecs
      }
    } else {
      newTimeRemainingMins = this.state.timeRemainingMins - 1
      if (this.state.timeRemainingSecs === 0 || this.state.timeRemainingSecs === '00') {
        newTimeRemainingSecs = 59
      } else {
        newTimeRemainingSecs = this.state.timeRemainingSecs -  1
      }
    }
    this.setState({
      timeRemainingMins: newTimeRemainingMins,
      timeRemainingSecs: newTimeRemainingSecs,
    })
    this.listenForNorify()
  },
  start: function() {
    clearInterval(this.intervalSec)
    this.intervalSec = setInterval(this.tick, 1000)
    const currentTask = find(this.state.tasksList, {current: true})
    if (!currentTask || currentTask.task !== 'Break') {
      this.intervalMin = setInterval(this.tickMinPomo, 1000 * 60)
    } else {
      this.intervalMin = setInterval(this.tickMinBreak, 1000 * 60)
    }
  },
  pause: function() {
    clearInterval(this.intervalSec)
    clearInterval(this.intervalMin)
  },
  resetTasks: function() {
    this.setState(this.getInitialState())
    window.localStorage.setItem('ketchupState', '')
  },
  listenForNorify: function() {
    if (this.state.timeRemainingMins === 0 && this.state.timeRemainingSecs === '00') {
      var audio = new Audio('assets/ding.ogg')
      audio.play()
    }
  },
  componentDidUpdate: function() {
{'fraction_non_alphanumeric': 0.13057620817843865, 'fraction_numerical': 0.010408921933085501, 'mean_word_length': 2.4746528898934455, 'pattern_counts': {'":': 0, '<': 53, '<?xml version=': 0, '>': 53, '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': '166232', 'n_tokens_mistral': 3586, 'n_tokens_neox': 3511, 'n_words': 643}