--- a/client/src/components/NoteInput.js Wed Jun 21 14:12:45 2017 +0200
+++ b/client/src/components/NoteInput.js Thu Jun 22 10:47:10 2017 +0200
@@ -1,12 +1,13 @@
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
-import { Form, FormControl, Button, Label } from 'react-bootstrap';
+import { Form, FormControl, Label } from 'react-bootstrap';
import moment from 'moment';
import PropTypes from 'prop-types';
import SlateEditor from './SlateEditor';
import * as notesActions from '../actions/notesActions';
+import * as userActions from '../actions/userActions';
class NoteInput extends Component {
@@ -25,6 +26,7 @@
}
onAddNoteClick = () => {
+
const plain = this.refs.editor.asPlain();
const raw = this.refs.editor.asRaw();
const html = this.refs.editor.asHtml();
@@ -44,6 +46,10 @@
setTimeout(() => this.refs.editor.focus(), 250);
}
+ onCheckboxChange = (e) => {
+ this.props.userActions.setAutoSubmit(e.target.checked);
+ }
+
componentDidMount() {
const text = this.refs.editor.asPlain();
this.setState({ buttonDisabled: text.length === 0 });
@@ -68,7 +74,13 @@
<Form>
<div className="editor">
<div className="editor-left">
- <SlateEditor ref="editor" onChange={this.onEditorChange} onEnterKeyDown={this.onAddNoteClick} />
+ <SlateEditor ref="editor"
+ onChange={this.onEditorChange}
+ onEnterKeyDown={this.onAddNoteClick}
+ onButtonClick={this.onAddNoteClick}
+ onCheckboxChange={this.onCheckboxChange}
+ isChecked={this.props.autoSubmit}
+ isButtonDisabled={this.state.buttonDisabled} />
</div>
<div className="editor-right">
<FormControl
@@ -79,19 +91,21 @@
/>
</div>
</div>
- <Button disabled={this.state.buttonDisabled} bsStyle="primary" type="button" onClick={this.onAddNoteClick}>Add Note</Button>
</Form>
);
}
}
function mapStateToProps(state, props) {
- return {};
+ return {
+ autoSubmit: state.autoSubmit
+ };
}
function mapDispatchToProps(dispatch) {
return {
notesActions: bindActionCreators(notesActions, dispatch),
+ userActions: bindActionCreators(userActions, dispatch),
}
}