<commit_before>import React, {Component} from 'react';

class Clock extends Component {
  constructor(props) {
    super(props);
    //hours minutes seconds will be in state
    //set the initial state to times locked in
    this.state = {'time': this.setClock(props)};
  }

  componentWillReceiveProps(nextProps) {
    console.log('componentWillRecieveProps fired')
    this.setState({'time': this.setClock(nextProps)});
    
    //trigger the timer if the button is pressed
    if(nextProps.info.locked) {
      this.timerID = setInterval( () => this.tick(), 1000);
    } else {
      clearInterval(this.timerID);
    }
  }

  setClock(time) {
    time = Number.parseInt(time.info.Work);
    let work_hours = time > 60 ? Math.floor(time / 60) : 0;
    let work_minutes = time <= 60 ? time : time % 60;
    let work_seconds = 0;
    return [work_hours, work_minutes, work_seconds];
  }

  tick() {
    let time = this.state.time;

    if (time[2] === 0 && time[1] !== 0) {
      time[2] = 59;
      time[1]--;
    } else {
      time[2]--;
    }

    if(time[1] === 0 && time[0] !== 0 && time[2] === 0){
      time[0]--;
      time[1] = 59;
    }

    if(time[0] + time[1] + time[2] === 0) {
      //time is up
    }

    this.setState({'time': time});
  }

  render() {
    let timer_hours = this.state.time[0];
    let timer_minutes =  this.state.time[1];
    let timer_seconds = this.state.time[2];

    return (
      <div className="col-sm-12 col-md-12 text-center">
        <h3>Work</h3>
            <span style={{display: 'inline-block', padding: '0 1.5rem 0 3rem'}}>
              {timer_hours}
              <p>Hours</p>
            </span>
            <span style={{display: 'inline-block'}}>:</span>
            <span style={{display: 'inline-block', padding: '0 1.5rem'}}>
              {timer_minutes}
              <p>Minutes</p>
            </span>
            <span style={{display: 'inline-block'}}>:</span>
            <span style={{display: 'inline-block', padding: '0 1.5rem'}}>
              {timer_seconds}
              <p>Seconds</p>
            </span>
      </div>
    )
  }
}

export default Clock;<commit_msg>Clock visual working<commit_after>import React, {Component} from 'react';

class Clock extends Component {
  constructor(props) {
    super(props);
    this.session = 'Work';
    this.state = {'time': this.setClock(props), };
  }

  componentDidMount() {
    this.updateCanvas();
  }

  componentWillReceiveProps(nextProps) {
    this.setState({'time': this.setClock(nextProps)});

    //trigger the timer if the button is pressed
    console.log('before if');
    if(nextProps.info.locked) {
      console.log('interval set');
      this.timerID = setInterval( () => this.tick(), 1000);
    } else {
      console.log('else');
      clearInterval(this.timerID);
    }
  }

  setClock(time) {
    time = Number.parseInt(this.props.info[this.session]);
    let timeInSeconds = time * 60;
    let hours = time > 60 ? Math.floor(time / 60) : 0;
    let minutes = time <= 60 ? time : time % 60;
    let seconds = 0;
    return [hours, minutes, seconds, timeInSeconds];
  }

  updateCanvas() {
    console.log(this);
    const ctx = this.refs.canvas.getContext('2d');
    try {
      ctx.clearRect(0, 0, 800, 800);
    } catch(e) {}
    let denominator = this.props.info[this.session] * 60;
    console.log('numerator', this.state.time[3], 'denominator', denominator);
    ctx.strokeStyle = 'cornflowerblue';
    ctx.lineWidth = 20;
    ctx.beginPath();
    ctx.arc(250,250,225, 0, (this.state.time[3] / denominator) * 0.999 * (2 * Math.PI));
    ctx.stroke();
  }

  tick() {
    let time = this.state.time;

    //time's up! switch to break time! woohoo! party!
    if(time[0] + time[1] + time[2] === 0) {
      clearInterval(this.timerID);
      this.session = 'Break';
      this.componentWillReceiveProps(this.props);
    } else {
      //if out of seconds get more from minutes.
      if (time[2] === 0 && time[1] !== 0) {
        time[2] = 59;
        time[1]--;
      } else {
        time[2]--;
      }

      //if out of minutes get more from hours.
      if(time[1] === 0 && time[0] !== 0 && time[2] === 0){
        time[0]--;
        time[1] = 59;
      }
    }

    this.state.time[3]--;
    this.updateCanvas();
    this.setState({'time': time});
  }

  render() {
    let timer_hours = this.state.time[0];
    let timer_minutes =  this.state.time[1];
    let timer_seconds = this.state.time[2];
    let inline = {display: 'inline-block'};

    return (
      <div className="col-sm-12 col-md-12 text-center">
        <h3>Work</h3>
          <span style={{display: 'inline-block', padding: '0 1.5rem 0 3rem'}}>
            {timer_hours}
            <p>Hours</p>
          </span>
          <span style={inline}>:</span>
          <span style={{display: 'inline-block', padding: '0 1.5rem'}}>
            {timer_minutes}
            <p>Minutes</p>
          </span>
          <span style={inline}>:</span>
          <span style={{display: 'inline-block', padding: '0 1.5rem'}}>
            {timer_seconds}
            <p>Seconds</p>
          </span>
          <canvas ref="canvas" style={{transform: 'rotate(-90deg)'}} width={500} height={500} ></canvas>
      </div>
    )
  }
}

export default Clock;
{'fraction_non_alphanumeric': 0.17298533053915033, 'fraction_numerical': 0.029529434177938654, 'mean_word_length': 2.268991282689913, 'pattern_counts': {'":': 0, '<': 47, '<?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': '2389179', 'n_tokens_mistral': 1880, 'n_tokens_neox': 1756, 'n_words': 387}