<commit_before>import React from 'react';

import Clock         from 'Clock';
import CountdownForm from 'CountdownForm';
import Controls      from 'Controls';

var Countdown = React.createClass({
  getInitialState: function () {
    return {
      count: 0,
      countdownStatus: 'stopped'
    };
  },
  componentDidUpdate: function (prevProps, prevState) {
    if(this.state.countdownStatus !== prevState.countdownStatus) {
      switch(this.state.countdownStatus) {
        case 'running':
          this.startTimer();
          break;

        case 'stopped':
          this.setState({ count: 0 });
          // Fall through

        case 'paused':
          clearInterval(this.timer);
          this.timer = undefined;
          break;
      }
    }
  },
  render: function () {
    let {count, countdownStatus} = this.state;

    const renderControlsArea = () => {
      if(countdownStatus !== 'stopped') {
        return <Controls countdownStatus={countdownStatus} onStatusChange={this.handleStatusChange} />;
      }
      else {
        return <CountdownForm onSetCountdown={this.handleSetCountdown}/>;
      }
    }

    return (
      <div>
        <Clock totalSeconds={count} />
        {renderControlsArea()}
      </div>
    )
  },
  handleSetCountdown: function (seconds) {
    this.setState({
      count: seconds,
      countdownStatus: 'running'
    });
  },
  startTimer: function () {
    this.timer = setInterval(() => {
      let newCount = this.state.count - 1;

      this.setState({ count: newCount >= 0 ? newCount : 0 });
    }, 1000);
  },
  handleStatusChange: function (newStatus) {
    this.setState({ countdownStatus: newStatus });
  }
});

module.exports = Countdown;
<commit_msg>Update Countdown to stop when complete<commit_after>import React from 'react';

import Clock         from 'Clock';
import CountdownForm from 'CountdownForm';
import Controls      from 'Controls';

var Countdown = React.createClass({
  getInitialState: function () {
    return {
      count: 0,
      countdownStatus: 'stopped'
    };
  },
  componentWillUnmount: function () {
    clearInterval(this.timer);
    this.timer = undefined;
  },
  componentDidUpdate: function (prevProps, prevState) {
    if(this.state.countdownStatus !== prevState.countdownStatus) {
      switch(this.state.countdownStatus) {
        case 'running':
          this.startTimer();
          break;

        case 'stopped':
          this.setState({ count: 0 });
          // Fall through

        case 'paused':
          clearInterval(this.timer);
          this.timer = undefined;
          break;
      }
    }
  },
  render: function () {
    let {count, countdownStatus} = this.state;

    const renderControlsArea = () => {
      if(countdownStatus !== 'stopped') {
        return <Controls countdownStatus={countdownStatus} onStatusChange={this.handleStatusChange} />;
      }
      else {
        return <CountdownForm onSetCountdown={this.handleSetCountdown}/>;
      }
    }

    return (
      <div>
        <Clock totalSeconds={count} />
        {renderControlsArea()}
      </div>
    )
  },
  handleSetCountdown: function (seconds) {
    this.setState({
      count: seconds,
      countdownStatus: 'running'
    });
  },
  startTimer: function () {
    this.timer = setInterval(() => {
      let newCount = this.state.count - 1;

      this.setState({ count: newCount >= 0 ? newCount : 0 });

      if(newCount === 0) {
        this.setState({ countdownStatus: 'stopped' });
      }
    }, 1000);
  },
  handleStatusChange: function (newStatus) {
    this.setState({ countdownStatus: newStatus });
  }
});

module.exports = Countdown;

{'fraction_non_alphanumeric': 0.12987369577155408, 'fraction_numerical': 0.005216913783635365, 'mean_word_length': 2.449810606060606, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 19, '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': '3857258', 'n_tokens_mistral': 1083, 'n_tokens_neox': 1057, 'n_words': 225}