client/src/components/NoteInput.js
author ymh <ymh.work@gmail.com>
Wed, 31 May 2017 18:08:22 +0200
changeset 8 6f572b6b6be3
parent 5 5c91bfa8fcde
child 12 48ddaa42b810
permissions -rw-r--r--
try to make tests work again

import React, {Component} from 'react';

import { Form, FormGroup, Button } from 'react-bootstrap';

import PropTypes from 'prop-types';
import SlateEditor from './SlateEditor';

class NoteInput extends Component {
  constructor(props) {
    super(props);

    this.state = {value: ''};

    this.onAddNoteClick = this.onAddNoteClick.bind(this);
    this.handleChange = this.handleChange.bind(this);
  }

  handleChange(event) {
    this.setState({value : event.target.value});
  }

  onAddNoteClick(event) {
    //const text = this.refs.editor.asPlain();
    if(this.state.value && this.state.value.length > 0) {
      this.props.addNote(this.state.value);
      this.refs.editor.clear();
    }
  }

  render() {
    return (
      <Form>
        <FormGroup>
          <SlateEditor ref="editor" onChange={this.handleChange} />
        </FormGroup>
        <Button type="button" onClick={this.onAddNoteClick}>Add Note</Button>
      </Form>
    );
  }
}

NoteInput.propTypes = {
  addNote: PropTypes.func.isRequired
};

export default NoteInput;