<commit_before>import React from 'react';
import { Row, Col, Button } from 'react-materialize';
import { createEditorState } from 'medium-draft';
import { connect } from 'react-redux';
import request from 'superagent';

import * as a from './../actions.js';

const mapStateToProps = state => ({
  username: state.username
});
const mapDispatchToProps = dispatch => ({
  loadNote: (newEditorState, title) => {
    dispatch(a.onTextEditorChange(newEditorState));
    dispatch(a.onSessionTitleCreate(title));
  },
  loadTranscript: (newEditorState) => {
    dispatch(a.onSpeechEditorChange(newEditorState));
  },
  loadCanvas: (newCanvasState) => {
    dispatch(a.onCanvasChange(newCanvasState));
  },
  deleteNote: (noteId, username) => (
    dispatch(a.deleteSession(noteId, username))
  )
});

class NoteItem extends React.Component {
  constructor(props) {
    super(props);

    this.state = {
      displayShare: false,
      email: ''
    };

    this.toggleDisplayShare = () => {
      this.setState({
        displayShare: !this.state.displayShare
      });
    };

    // take noteId and e-mail, send post request to db to get
    // db to look up the noteId and create a new noteId under
    // that user's name
    this.shareNote = (e) => {
      e.preventDefault();
      this.toggleDisplayShare();
      request
        .post('/api/social/share-note')
        .send({
          noteId: this.props.noteId,
          email: this.state.email,
          originEmail: this.props.username
        })
        .end((err, res) => {
          if (err) {
            console.log('Error sharing notes ... ', err);
          } else {
            // success
            console.log('Shared the note!');
          }
        });
    };
  }

  render() {
    return (
      <li>
        <div className="card red darken-1">
          <div className="card-content white-text center-align">
            <span className="center-align card-title">{this.props.title}</span>
            <Row className="center-align">

              <Col s={4} className="center-align">
                <Button
                  onClick={() => {
                    // get new store state for editors
                    const newNoteState =
                      createEditorState(JSON.parse(this.props.notesText));
                    const newTranscriptState =
                      createEditorState(JSON.parse(this.props.transcriptText));
                    // load each editor onto page.
                    this.props.loadNote(newNoteState, this.props.title);
                    this.props.loadTranscript(newTranscriptState);
                    this.props.loadCanvas(JSON.parse(this.props.canvas));
                  }}
                  waves="light"
                  icon="open_in_browser"
                  className="red"
                />
              </Col>

              <Col s={4}>
                <Button
                  onClick={() => {
                    this.props.deleteNote(this.props.noteId, this.props.username);
                  }}
                  waves="light"
                  icon="delete_forever"
                  className="red"
                />
              </Col>

              <Col s={4}>
                <Button
                  onClick={this.toggleDisplayShare}
                  waves="light"
                  icon="rss_feed"
                  className="red"
                />
              </Col>

              {this.state.displayShare ?
                <form onSubmit={this.shareNote} className="">
                  <input
                    type="email"
                    id="email"
                    placeholder="E-mail"
                    className="center-align"
                    onChange={e => this.setState({ email: e.target.value })}
                  />
                  <input type="submit" value="share" />
                </form>
                : null
              }

            </Row>
          </div>
        </div>
      </li>
    );
  }
}

NoteItem.propTypes = {
  title: React.PropTypes.string,
  noteId: React.PropTypes.string,
  username: React.PropTypes.string,
  transcriptText: React.PropTypes.string,
  notesText: React.PropTypes.string,
  loadNote: React.PropTypes.func,
  loadTranscript: React.PropTypes.func,<commit_msg>fix conflict<commit_after>import React from 'react';
import { Row, Col, Button } from 'react-materialize';
import { createEditorState } from 'medium-draft';
import { connect } from 'react-redux';
import request from 'superagent';

import * as a from './../actions.js';

const mapStateToProps = state => ({
  username: state.username
});
const mapDispatchToProps = dispatch => ({
  loadNote: (newEditorState, title) => {
    dispatch(a.onTextEditorChange(newEditorState));
    dispatch(a.onSessionTitleCreate(title));
  },
  loadTranscript: (newEditorState) => {
    dispatch(a.onSpeechEditorChange(newEditorState));
  },
  loadCanvas: (newCanvasState) => {
    dispatch(a.onCanvasChange(newCanvasState));
  },
  deleteNote: (noteId, username) => (
    dispatch(a.deleteSession(noteId, username))
  )
});

class NoteItem extends React.Component {
  constructor(props) {
    super(props);

    this.state = {
      displayShare: false,
      email: ''
    };

    this.toggleDisplayShare = () => {
      this.setState({
        displayShare: !this.state.displayShare
      });
    };

    // take noteId and e-mail, send post request to db to get
    // db to look up the noteId and create a new noteId under
    // that user's name
    this.shareNote = (e) => {
      e.preventDefault();
      this.toggleDisplayShare();
      request
        .post('/api/social/share-note')
        .send({
          noteId: this.props.noteId,
          email: this.state.email,
          originEmail: this.props.username
        })
        .end((err, res) => {
          if (err) {
            console.log('Error sharing notes ... ', err);
          } else {
            console.log('Shared the note!');
          }
        });
    };
  }

  render() {
    return (
      <li>
        <div className="card red darken-1">
          <div className="card-content white-text center-align">
            <span className="center-align card-title">{this.props.title}</span>
            <Row className="center-align">

              <Col s={4} className="center-align">
                <Button
                  onClick={() => {
                    // get new store state for editors
                    const newNoteState =
                      createEditorState(JSON.parse(this.props.notesText));
                    const newTranscriptState =
                      createEditorState(JSON.parse(this.props.transcriptText));
                    // load each editor onto page.
                    this.props.loadNote(newNoteState, this.props.title);
                    this.props.loadTranscript(newTranscriptState);
                    this.props.loadCanvas(JSON.parse(this.props.canvas));
                  }}
                  waves="light"
                  icon="open_in_browser"
                  className="red"
                />
              </Col>

              <Col s={4}>
                <Button
                  onClick={() => {
                    this.props.deleteNote(this.props.noteId, this.props.username);
                  }}
                  waves="light"
                  icon="delete_forever"
                  className="red"
                />
              </Col>

              <Col s={4}>
                <Button
                  onClick={this.toggleDisplayShare}
                  waves="light"
                  icon="rss_feed"
                  className="red"
                />
              </Col>

              {this.state.displayShare ?
                <form onSubmit={this.shareNote} className="">
                  <input
                    type="email"
                    id="email"
                    placeholder="E-mail"
                    className="center-align"
                    onChange={e => this.setState({ email: e.target.value })}
                  />
                  <input type="submit" value="share" />
                </form>
                : null
              }

            </Row>
          </div>
        </div>
      </li>
    );
  }
}

NoteItem.propTypes = {
  title: React.PropTypes.string,
  noteId: React.PropTypes.string,
  username: React.PropTypes.string,
  transcriptText: React.PropTypes.oneOfType([
    React.PropTypes.string,
    React.PropTypes.instanceOf(Object)
  ]),
  notesText: React.PropTypes.oneOfType([
    React.PropTypes.string,
    React.PropTypes.instanceOf(Object)
  ]),
  loadNote: React.PropTypes.func,
  loadTranscript: React.PropTypes.func,
{'fraction_non_alphanumeric': 0.12422502870264064, 'fraction_numerical': 0.0009184845005740528, 'mean_word_length': 1.5681014150943395, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 73, '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': '792554', 'n_tokens_mistral': 2378, 'n_tokens_neox': 2287, 'n_words': 439}