<commit_before>import React, {Component} from 'react';
import _ from 'lodash';
import { connect } from 'react-redux';
import PropTypes from 'prop-types';
import muiThemeable from 'material-ui/styles/muiThemeable';
import {injectIntl, intlShape} from 'react-intl';
import { Activity } from '../../components/Activity';
import * as taskActions from '../../store/tasks/actions';
import {List, ListItem} from 'material-ui/List';
import Divider from 'material-ui/Divider';
import FontIcon from 'material-ui/FontIcon';
import IconButton from 'material-ui/IconButton';
import TextField from 'material-ui/TextField';
import FloatingActionButton from 'material-ui/FloatingActionButton';
import CircularProgress from 'material-ui/CircularProgress';
import Avatar from 'material-ui/Avatar';
import Paper from 'material-ui/Paper';

const styles={
  center_container:{
    display: 'flex',
    alignItems: 'center',
    justifyContent: 'center',
    flexDirection: 'column',
    margin: 16,
  },
  main_container:{
    float: 'left',
    position: 'relative',
    left: '50%',
  },

  fixer_container:{
    float: 'left',
    position: 'relative',
    left: '-50%',
  },

  button: {
    position: 'fixed',
    zIndex:3,
    bottom: 35,
    marginLeft: -24
  },

  text_input: {
    position: 'fixed',
    zIndex:3,
    bottom: 35,
    marginLeft: -155
  }
}


class Tasks extends Component {

  constructor(props) {
    super(props);
    this.name = null;
    this.new_task_title = null;
  }

  componentWillMount() {
    this.props.loadTasks();
  }

  handleKeyDown = (event, onSucces) => {

    if(event.keyCode===13){
      onSucces();
    }
  }

  componentWillUnmount() {
    this.props.unloadTasks();
  }

  componentDidUpdate() {
    // TODO: just a fast solution. Repair it ASAP
    window.scrollTo(0, 100000)
  }

  handleAddTask = () => {
    const {createTask, auth}=this.props;

    const newTask={
      title: this.name.getValue(),
      userName: auth.displayName,
      userPhotoURL: auth.photoURL,
      userId: auth.uid,
      completed: false
    }

    createTask(newTask);
  }

  handleUpdateTask = (key, task) => {
    const { updateTask }=this.props;

    const newTask= {...task, title: this.new_task_title.getValue()};

    updateTask(key, newTask);
  }

  renderPrimaryText = (task, key) =>{
    const { tasks} =this.props;

    return tasks.isEditing===key? <div>
      <TextField
        id="new_task_title"
        style={{height: 26}}
        underlineShow={false}
        defaultValue={task.title}
        onKeyDown={(event)=>{this.handleKeyDown(event, ()=>{this.handleUpdateTask(key, task)})}}
        ref={(field) => { this.new_task_title = field; this.new_task_title && this.new_task_title.focus(); }}
        type="Text"
      />
    </div>:  task.title;

  }

  rednerTasks(tasks) {
    const {deleteTask, muiTheme, setIsEditing, auth} =this.props;

    return _.map(tasks.list, (task, key) => {

      const isEditing=tasks.isEditing===key;

      return <div key={key}>
        <ListItem
          key={key}
          onTouchTap={task.userId===auth.uid?()=>{setIsEditing(key);}:undefined}
          leftAvatar={<Avatar src={task.userPhotoURL} />}
          primaryText={this.renderPrimaryText(task, key)}
          secondaryText={isEditing?undefined:task.userName}
          id={key}
          rightIconButton={<div>
            {task.userId===auth.uid && <div>
              <IconButton
                onTouchTap={isEditing?()=>{this.handleUpdateTask(key,task)}:()=>{setIsEditing(key);}}>
                <FontIcon className="material-icons" color={muiTheme.palette.primary1Color}>{isEditing?'save':'edit'}</FontIcon>
              </IconButton>

              <IconButton
                onTouchTap={isEditing?()=>{setIsEditing(false);}:()=>{deleteTask(key);}}>
                <FontIcon className="material-icons" color={'red'}>{isEditing?'highlight_off':'delete'}</FontIcon>
              </IconButton>
            </div><commit_msg>Implementation of tasks completed feature<commit_after>import React, {Component} from 'react';
import _ from 'lodash';
import { connect } from 'react-redux';
import PropTypes from 'prop-types';
import muiThemeable from 'material-ui/styles/muiThemeable';
import {injectIntl, intlShape} from 'react-intl';
import { Activity } from '../../components/Activity';
import * as taskActions from '../../store/tasks/actions';
import {List, ListItem} from 'material-ui/List';
import Divider from 'material-ui/Divider';
import FontIcon from 'material-ui/FontIcon';
import IconButton from 'material-ui/IconButton';
import TextField from 'material-ui/TextField';
import FloatingActionButton from 'material-ui/FloatingActionButton';
import CircularProgress from 'material-ui/CircularProgress';
import Avatar from 'material-ui/Avatar';
import Paper from 'material-ui/Paper';
import {transparent, green800} from 'material-ui/styles/colors';

const styles={
  center_container:{
    display: 'flex',
    alignItems: 'center',
    justifyContent: 'center',
    flexDirection: 'column',
    margin: 16,
  },
  main_container:{
    float: 'left',
    position: 'relative',
    left: '50%',
  },

  fixer_container:{
    float: 'left',
    position: 'relative',
    left: '-50%',
  },

  button: {
    position: 'fixed',
    zIndex:3,
    bottom: 35,
    marginLeft: -24
  },

  text_input: {
    position: 'fixed',
    zIndex:3,
    bottom: 35,
    marginLeft: -155
  }
}


class Tasks extends Component {

  constructor(props) {
    super(props);
    this.name = null;
    this.new_task_title = null;
  }

  componentWillMount() {
    this.props.loadTasks();
  }

  handleKeyDown = (event, onSucces) => {

    if(event.keyCode===13){
      onSucces();
    }
  }

  componentWillUnmount() {
    this.props.unloadTasks();
  }

  componentDidUpdate() {
    // TODO: just a fast solution. Repair it ASAP
    window.scrollTo(0, 100000)
  }

  handleAddTask = () => {
    const {createTask, auth}=this.props;

    const newTask={
      title: this.name.getValue(),
      userName: auth.displayName,
      userPhotoURL: auth.photoURL,
      userId: auth.uid,
      completed: false
    }

    createTask(newTask);
  }

  handleUpdateTask = (key, task) => {
    const { updateTask }=this.props;

    //const newTask= {...task, title: this.new_task_title.getValue()};

    updateTask(key, task);
  }

  renderPrimaryText = (task, key) =>{
    const { tasks} =this.props;

    return tasks.isEditing===key? <div>
      <TextField
        id="new_task_title"
        style={{height: 26}}
        underlineShow={false}
        defaultValue={task.title}
        onKeyDown={(event)=>{this.handleKeyDown(event, ()=>{this.handleUpdateTask(key, {...task, title: this.new_task_title.getValue()})})}}
        ref={(field) => { this.new_task_title = field; this.new_task_title && this.new_task_title.focus(); }}
        type="Text"
      />
    </div>:  <div>
      {task.title}
    </div>;

  }

  rednerTasks(tasks) {
    const {deleteTask, muiTheme, setIsEditing, auth} =this.props;

    return _.map(tasks.list, (task, key) => {

      const isEditing=tasks.isEditing===key;

      return <div key={key}>
        <ListItem
          key={key}
          onTouchTap={()=>{this.handleUpdateTask(key,{...task, completed: !task.completed})}}
          leftAvatar={
            task.completed?
            <Avatar
              icon={<FontIcon className="material-icons" >check_circle</FontIcon>}
              color={green800}
              backgroundColor={transparent}
            />
            :
            <Avatar src={task.userPhotoURL} />
          }
          primaryText={this.renderPrimaryText(task, key)}
          secondaryText={isEditing?undefined:task.userName}
          id={key}
          rightIconButton={<div>
            {task.userId===auth.uid && <div>
              <IconButton
                onTouchTap={isEditing?()=>{this.handleUpdateTask(key,{...task, title: this.new_task_title.getValue()})}:()=>{setIsEditing(key);}}>
                <FontIcon className="material-icons" color={muiTheme.palette.primary1Color}>{isEditing?'save':'edit'}</FontIcon>
              </IconButton>

              <IconButton
                onTouchTap={isEditing?()=>{setIsEditing(false);}:()=>{deleteTask(key);}}>
                <FontIcon className="material-icons" color={'red'}>{isEditing?'highlight_off':'delete'}</FontIcon>
              </IconButton>
            </div>
{'fraction_non_alphanumeric': 0.1535990481856038, 'fraction_numerical': 0.007614515169541939, 'mean_word_length': 2.957627118644068, 'pattern_counts': {'":': 0, '<': 42, '<?xml version=': 0, '>': 66, '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': '3719267', 'n_tokens_mistral': 2744, 'n_tokens_neox': 2640, 'n_words': 506}