<commit_before>import React from 'react';
import PropTypes from 'prop-types';
import Timer from './Timer';
import ButtonsGroup from './ButtonsGroup';
import Spinner from '../layout/Spinner';
import { formatDate, formatTime } from '../../helpers';

class Task extends React.Component {
  state = {
    editName: '',
    showInput: false,
    showTimer: false,
    spinner: false,
  };

  componentWillReceiveProps(nextProps) {
    if (nextProps) {
      this.setState({ spinner: false });
    }
  }

  showTimer = () => {
    this.setState(state => ({
      showTimer: !state.showTimer,
    }));
  }

  handleNameInput = (e) => {
    this.setState({ editName: e.target.value });
  }

  handleShowInput = (name) => {
    this.setState({
      showInput: !this.state.showInput,
      editName: name,
    });
  }

  handleRenaming = (id, name) => {
    this.props.handleRename(id, name);
    this.setState({
      showInput: false,
      spinner: true
    });
  }

  handleEnterButton = (id, name) => {
    this.props.handleRename(id, name);
    this.setState({
      showInput: false,
      spinner: true
    });
  }

  render() {
    const { editName, showInput, showTimer } = this.state;
    const { id, name, done, handleAddingTimeLog, projectId } = this.props;
    const TimerComponent = showTimer ? (
      <Timer
        key={`timer${id}`}
        id={id}
        taskName={name}
        project={projectId}
        handleAddingTimeLog={handleAddingTimeLog}
      />
    ) : null;
    const doneButtonValue = done ? 'undone' : 'done';
    const doneClass = done ? 'tasks__list-item--done' : 'tasks__list-item';
    const hideOrNot = showInput ? 'none' : '';
    const newDate = this.props.updated ? formatDate(this.props.updated) : '';
    const dateString = this.props.updated ? 'Done:' : '';

    if (this.state.spinner) {
      return <Spinner />;
    }

    return (
      <li className={`${doneClass}`}>
        <p style={{ display: hideOrNot }} className="tasks__list-name">
          <span>{name}</span>
          <span className="pretty-time">
            {formatTime(this.props.timeSpent)}
          </span>
        </p>
        {dateString !== '' ? (
          <span className="tasks__list-date">
            <strong>{dateString} </strong>
            {newDate}
          </span>
        ) : null}

        {showInput ? (
          <input
            type="text"
            onKeyPress={e => {
              if (e.charCode === 13) {
                this.handleEnterButton(id, editName);
              }
            }}
            value={editName}
            className="tasks__list-input"
            onChange={this.handleNameInput}
          />
        ) : null}

        <ButtonsGroup
          {...this.props}
          {...this.state}
          showTimer={this.showTimer}
          handleShowInput={this.handleShowInput}
          handleRenaming={() => this.handleRenaming(id, editName)}
          doneButtonValue={doneButtonValue}
        />
        {done ? null : TimerComponent}
      </li>
    );
  }
}

Task.defaultProps = {
  updated: undefined,
  projectId: '',
  handleAddingTimeLog: null,
};

Task.propTypes = {
  name: PropTypes.string.isRequired,
  handleDelete: PropTypes.func.isRequired,
  handleRename: PropTypes.func.isRequired,
  taskDone: PropTypes.func.isRequired,
  done: PropTypes.bool.isRequired,
  id: PropTypes.string.isRequired,
  updated: PropTypes.string,
  timeSpent: PropTypes.number.isRequired,
  handleAddingTimeLog: PropTypes.func,
  projectId: PropTypes.string,
};

export default Task;<commit_msg>editing task now supports changing the project<commit_after>import React from 'react';
import PropTypes from 'prop-types';
import Timer from './Timer';
import ButtonsGroup from './ButtonsGroup';
import Spinner from '../layout/Spinner';
import { formatDate, formatTime } from '../../helpers';
import ProjectsSelect from '../projects/ProjectsSelect';

class Task extends React.Component {
  state = {
    editName: '',
    showInput: false,
    showTimer: false,
    spinner: false,
    categoryID: '',
  };

  componentWillReceiveProps(nextProps) {
    if (nextProps) {
      this.setState({ spinner: false });
    }
  }

  showTimer = () => {
    this.setState(state => ({
      showTimer: !state.showTimer,
    }));
  }

  handleNameInput = (e) => {
    this.setState({ editName: e.target.value });
  }

  handleShowInput = (name) => {
    this.setState({
      showInput: !this.state.showInput,
      editName: name,
    });
  }

  handleRenaming = (id, name, categoryID) => {
    this.props.handleRename(id, name, categoryID);
    this.setState({
      showInput: false,
      spinner: true
    });
  }

  handleEnterButton = (id, name) => {
    this.props.handleRename(id, name);
    this.setState({
      showInput: false,
      spinner: true
    });
  }

  changeSelect = (e) => {
    this.setState({
      categoryID: e.target.value
    });
  }

  render() {
    const { editName, showInput, showTimer, categoryID } = this.state;
    const { id, name, done, handleAddingTimeLog, projectId } = this.props;
    const TimerComponent = showTimer ? (
      <Timer
        key={`timer${id}`}
        id={id}
        taskName={name}
        project={projectId}
        handleAddingTimeLog={handleAddingTimeLog}
      />
    ) : null;
    const doneButtonValue = done ? 'undone' : 'done';
    const doneClass = done ? 'tasks__list-item--done' : 'tasks__list-item';
    const hideOrNot = showInput ? 'none' : '';
    const newDate = this.props.updated ? formatDate(this.props.updated) : '';
    const dateString = this.props.updated ? 'Done:' : '';

    if (this.state.spinner) {
      return <Spinner />;
    }

    return (
      <li className={`${doneClass}`}>
        <p style={{ display: hideOrNot }} className="tasks__list-name">
          <span>{name}</span>
          <span className="pretty-time">
            {formatTime(this.props.timeSpent)}
          </span>
        </p>
        {dateString !== '' ? (
          <span className="tasks__list-date">
            <strong>{dateString} </strong>
            {newDate}
          </span>
        ) : null}

        {showInput ? (
          <div className="tasks__list-input">
            <input
              type="text"
              onKeyPress={e => {
                if (e.charCode === 13) {
                  this.handleEnterButton(id, editName, categoryID);
                }
              }}
              value={editName}
              onChange={this.handleNameInput}
            />
            <ProjectsSelect
              parentID={this.state.categoryID}
              projects={this.props.projects}
              changeSelect={this.changeSelect}
            />
          </div>
        ) : null}

        <ButtonsGroup
          {...this.props}
          {...this.state}
          showTimer={this.showTimer}
          handleShowInput={this.handleShowInput}
          handleRenaming={() => this.handleRenaming(id, editName, categoryID)}
          doneButtonValue={doneButtonValue}
        />
        {done ? null : TimerComponent}
      </li>
    );
  }
}

Task.defaultProps = {
  updated: undefined,
  projectId: '',
  handleAddingTimeLog: null,
};

Task.propTypes = {
  name: PropTypes.string.isRequired,
  handleDelete: PropTypes.func.isRequired,
  handleRename: PropTypes.func.isRequired,
  taskDone: PropTypes.func.isRequired,
  done: PropTypes.bool.isRequired,
  id: PropTypes.string.isRequired,
  updated: PropTypes.string,
  timeSpent: PropTypes.number.isRequired,
  projects: PropTypes.array.isRequired,
  handleAddingTimeLog: PropTypes.func,
  projectId: PropTypes.string,
};

export default Task;
{'fraction_non_alphanumeric': 0.14043837773986087, 'fraction_numerical': 0.000525003281270508, 'mean_word_length': 2.292999135695765, 'pattern_counts': {'":': 0, '<': 38, '<?xml version=': 0, '>': 55, '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': '2862655', 'n_tokens_mistral': 2312, 'n_tokens_neox': 2308, 'n_words': 440}