<commit_before>import React from 'react';

var Timer = React.createClass({
  getInitialState: function() {
    return {
      secondsElapsed: 1,
      message: 'Click the start button to begin!'
    };
  },

  getMinutes: function() {
    return Math.floor(this.state.secondsElapsed / 60);
  },

  getSeconds: function() {
    return (this.state.secondsElapsed % 60);
  },

  startTimer: function() {
    var startTimerState = this;
    startTimerState.setState({
      message: "Starting timer now! Let's code!"
    });

    // changes Home's state to timerOn true
    this.props.timerOn();

    this.incrementer = setInterval(function() {
      startTimerState.setState({
        secondsElapsed: (startTimerState.state.secondsElapsed + 1),
        message: 'Time Elapsed: ' + startTimerState.getMinutes() + ' Minutes & ' + startTimerState.getSeconds() + ' Seconds!'
      });
    }, 1000);

  },

  // stopTimer: function() {
  //   clearInterval(this.incrementer);
  // },

  resetTimer: function() {
    var resetTimerState = this;
      resetTimerState.setState({
        secondsElapsed: 0
      });

      if (this.state.secondsElapsed <= 60) {
        resetTimerState.setState({
          message: 'You took ' + ((this.state.secondsElapsed-1) % 60) + ' Seconds!'
        });
      } else {
        resetTimerState.setState({
          message: 'You took ' + Math.floor((this.state.secondsElapsed-1) / 60) + ' Minutes and ' + ((this.state.secondsElapsed-1) % 60) + ' Seconds!'
        });
      }

      clearInterval(this.incrementer);
  },

  render: function() {
    return (
      <div className="container">
      <center>
      <div className="row">
        <h1>{this.state.message}</h1>
        </div>
        <div className="row">
        <div className="col-sm-6">
        <button type="button" onClick={this.startTimer} className="btn btn-success pull-right">START</button>
        </div>
        <div className="col-sm-6">
        <button type="button" onClick={this.resetTimer} className="btn btn-primary pull-left">FINISH</button>
        </div>
        </div>
        </center>
        <br />
      </div>
    );
  }
});

module.exports = Timer;

// ES6 Version of Timer Component. WARNING: DOES NOT WORK!
// import React, { Component } from 'react';

// class Timer extends Component {
//   constructor(props) {
//     super(props);
//     this.state = {secondsElapsed: 0};
//   }
//
//   getMinutes() {
//     return Math.floor(this.state.secondsElapsed / 60);
//   }
//
//   getSeconds() {
//     return ('0' + this.state.secondsElapsed % 60).slice(-2);
//   }
//
//   startTimer() {
//     var startTimerState = this;
//
//     this.incrementer = setInterval(function() {
//       startTimerState.setState({
//         secondsElapsed: (startTimerState.state.secondsElapsed + 1)
//       });
//     }, 1000);
//
//   }
//
//   stopTimer() {
//     clearInterval(this.incrementer);
//   }
//
//   render() {
//     return (
//       <div className="container">
//         <h1>{this.getMinutes()}:{this.getSeconds()}</h1>
//         <button type="button" onClick={this.startTimer} className="btn btn-success">START</button>
//         <button type="button" onClick={this.stopTimer} className="btn btn-danger">STOP</button>
//       </div>
//     );
//   }
// }

// export default Timer;<commit_msg>[refactor] refactors timer to use ES6 code<commit_after>import React, { Component } from 'react';

class Timer extends Component {
  constructor(props) {
    super(props);
    this.state = {
      secondsElapsed: 1,
      message: 'Click the start button to begin!'
    }
  };

  getMinutes() {
    return Math.floor(this.state.secondsElapsed / 60);
  }

  getSeconds() {
    return (this.state.secondsElapsed % 60);
  }

  startTimer() {
    this.setState({
      message: 'Starting timer now! Let\'s code!'
    });

    this.props.startTimer();

    this.incrementer = setInterval(function() {
      this.setState({
        secondsElapsed: (this.state.secondsElapsed + 1),
        message: 'Time Elapsed: ' + this.getMinutes() + ' Minutes & ' + this.getSeconds() + ' Seconds!'
      });
    }.bind(this), 1000);
  }

  resetTimer() {
    this.setState({
      secondsElapsed: 0
    });

    if (this.state.secondsElapsed <= 60) {
      this.setState({
        message: 'You took ' + ((this.state.secondsElapsed-1) % 60) + ' Seconds!'
      });
    } else {
      this.setState({
        message: 'You took ' + Math.floor((this.state.secondsElapsed-1) / 60) + ' Minutes and ' + ((this.state.secondsElapsed-1) % 60) + ' Seconds!'
      });
    }
  }

  render() {
    return (
      <div className="container">
      <center>
      <div className="row">
        <h1>{this.state.message}</h1>
        </div>
        <div className="row">
        <div className="col-sm-6">
        <button type="button" onClick={this.startTimer.bind(this)} className="btn btn-success pull-right">START</button>
        </div>
        <div className="col-sm-6">
        <button type="button" onClick={this.resetTimer.bind(this)} className="btn btn-primary pull-left">FINISH</button>
        </div>
        </div>
        </center>
        <br />
      </div>
    );
  }
};

export default Timer;
{'fraction_non_alphanumeric': 0.16862367661212704, 'fraction_numerical': 0.013089509143407122, 'mean_word_length': 2.358758888170653, 'pattern_counts': {'":': 0, '<': 51, '<?xml version=': 0, '>': 49, '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': '4980151', 'n_tokens_mistral': 1703, 'n_tokens_neox': 1625, 'n_words': 316}