diff -r 49c5ea36d0a4 -r 772b73e31069 client/src/components/Note.js --- a/client/src/components/Note.js Thu Jun 22 12:37:53 2017 +0200 +++ b/client/src/components/Note.js Fri Jun 23 10:16:49 2017 +0200 @@ -1,22 +1,80 @@ -import React from 'react'; +import React, { Component } from 'react'; +import { connect } from 'react-redux'; +import { bindActionCreators } from 'redux'; import PropTypes from 'prop-types'; -import {formatTimestamp} from '../utils'; +import { formatTimestamp } from '../utils'; +import SlateEditor from './SlateEditor'; +import * as notesActions from '../actions/notesActions'; + +class Note extends Component { + + state = { + edit: false + } + + toggleEditMode = () => { + const { edit } = this.state; + this.setState({ edit: !edit }) + } + + onClickDelete = (e) => { + e.preventDefault(); + e.stopPropagation(); + + this.props.notesActions.deleteNote(this.props.note); + } -const Note = ({note}) => { - return ( -
- {formatTimestamp(note.startedAt)} - {formatTimestamp(note.finishedAt)} -
-
- { note.marginComment } + renderNoteContent() { + if (this.state.edit) { + return ( +
+ +
+ ) + } + + return ( +
+ ) + } + + render() { + return ( +
+ { formatTimestamp(this.props.note.startedAt) } + { formatTimestamp(this.props.note.finishedAt) } + { this.renderNoteContent() } +
+ { this.props.note.marginComment } +
+ + delete +
-
- ); -}; + ); + }; +} Note.propTypes = { note: PropTypes.object.isRequired }; -export default Note; +function mapStateToProps(state, props) { + return props; +} + +function mapDispatchToProps(dispatch) { + return { + notesActions: bindActionCreators(notesActions, dispatch), + } +} + +export default connect(mapStateToProps, mapDispatchToProps)(Note);