<commit_before>import React from 'react';
import Dialog from 'material-ui/Dialog';
import RaisedButton from 'material-ui/RaisedButton';
import ChipInputList from '../common/ChipInputList.jsx'



export default class SharePane extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      open: false,
      authors:[]
    };

    this.handleAuthorChange = this.handleAuthorChange.bind(this);
  }

  handleOpen = () => {
    this.setState({open: true});
  };

  handleClose = () => {
    this.setState({open: false});
  };

  componentWillMount(){
    this.loadAuthors();
  }

  componentWillReceiveProps(props){
    this.setState({open: props.value});
  }


  loadAuthors() {
    var suggestedAuthors = [{id:"<EMAIL>.", name :"Marko"},
    {id:"<EMAIL>", name :"Victor"},{id:"<EMAIL>", name :"Cedric"}];

    //loadSuggestedAuthors

    var suggestedAuthorsArray = []
    for (var i in suggestedAuthors) {
      suggestedAuthorsArray = suggestedAuthorsArray.concat([suggestedAuthors[i].name + " ("+suggestedAuthors[i].id+ ")"]);
    }
    this.setState({suggestedAuthors: suggestedAuthorsArray});
  }


  handleAuthorChange(value) {
    this.setState({authors : value});
    this.props.onChange("tags" , value);
  }

  render() {
    const actions = [
      <RaisedButton
        label="Cancel"
        primary={true}
        onTouchTap={this.handleClose}
        />,
      <RaisedButton
        label="Share"
        primary={true}
        onTouchTap={this.handleClose}
        style={{marginLeft:20}}
        />,
    ];

    return (
      <Dialog
        title="Share project with"
        actions={actions}
        modal={false}
        open={this.state.open}
        onRequestClose={this.handleClose}
        >
        <ChipInputList suggestions = {this.state.suggestedAuthors}
          onChange={this.handleAuthorChange}
          filtered ={true}
          value={this.state.authors}
          hintText={'Add authors...'}
          />

      </Dialog>
    );
  }
}
<commit_msg>Sharing functionality<commit_after>import React from 'react';
import Dialog from 'material-ui/Dialog';
import RaisedButton from 'material-ui/RaisedButton';
import ChipInputList from '../common/ChipInputList.jsx'



export default class SharePane extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      open: false,
      authors:[]
    };

    this.handleAuthorChange = this.handleAuthorChange.bind(this);
  }

  handleOpen = () => {
    this.setState({open: true});
  };

  handleClose = () => {
    this.setState({open: false});
  };


  shareProject =() =>{
    for (var i in this.state.authors) {
      var string = this.state.authors[i];
      var id = string.substring(string.lastIndexOf("(")+1, string.length-1);
      var shareURL =  "/api/projects/"+this.props.uuid+"/share/"+id
      fetch(shareURL, {
        method: 'POST',
        mode: 'no-cors',
        credentials: 'include',
        headers: {
          "Accept": "application/json",
        }
      }).then(response => response.json()).catch(ex => {
        console.error('parsing failes', ex);
      });
    }
    this.setState({open: false});
  }

  componentWillMount(){
    this.loadAuthors();
  }

  componentWillReceiveProps(props){
    this.setState({open: props.value});
  }


  loadAuthors() {
    var suggestedAuthors = [{id:"<EMAIL>.", name :"Marko"},
    {id:"<EMAIL>", name :"Victor"},{id:"<EMAIL>", name :"Cedric"}];

    //loadSuggestedAuthors

    var suggestedAuthorsArray = []
    for (var i in suggestedAuthors) {
      suggestedAuthorsArray = suggestedAuthorsArray.concat([suggestedAuthors[i].name + " ("+suggestedAuthors[i].id+ ")"]);
    }
    this.setState({suggestedAuthors: suggestedAuthorsArray});
  }


  handleAuthorChange(value) {
    this.setState({authors : value});
  }

  render() {
    const actions = [
      <RaisedButton
        label="Cancel"
        primary={true}
        onTouchTap={this.handleClose}
        />,
      <RaisedButton
        label="Share"
        primary={true}
        onTouchTap={this.shareProject}
        style={{marginLeft:20}}
        />,
    ];

    return (
      <Dialog
        title="Share project with"
        actions={actions}
        modal={false}
        open={this.state.open}
        onRequestClose={this.handleClose}
        >
        <ChipInputList suggestions = {this.state.suggestedAuthors}
          onChange={this.handleAuthorChange}
          filtered ={true}
          value={this.state.authors}
          hintText={'Add authors...'}
          />

      </Dialog>
    );
  }
}

{'fraction_non_alphanumeric': 0.15131004366812226, 'fraction_numerical': 0.0013100436681222707, 'mean_word_length': 2.6070866141732285, 'pattern_counts': {'":': 1, '<': 19, '<?xml version=': 0, '>': 26, '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': '2752001', 'n_tokens_mistral': 1447, 'n_tokens_neox': 1368, 'n_words': 234}