diff -r 76a4e4b11762 -r bf35a7737f94 client/src/components/NotesList.js --- a/client/src/components/NotesList.js Fri Jun 23 17:58:21 2017 +0200 +++ b/client/src/components/NotesList.js Fri Jun 23 18:01:40 2017 +0200 @@ -1,30 +1,100 @@ -import React from 'react'; - +import React, { Component } from 'react'; +import { connect } from 'react-redux'; +import { bindActionCreators } from 'redux'; import PropTypes from 'prop-types'; import Immutable from 'immutable'; +import { Alert, Modal, Button } from 'react-bootstrap'; +import Note from './Note'; +import * as notesActions from '../actions/notesActions'; -import { Alert } from 'react-bootstrap'; +class NotesList extends Component { + + state = { + editingNote: null, + noteToDelete: null, + showModal: false, + } + + enterEditMode = (note) => { + this.setState({ editingNote: note }); + } -import Note from './Note'; + closeNote = () => { + this.setState({ editingNote: null }); + } + + confirmDelete = (note) => { + this.setState({ + showModal: true, + noteToDelete: note + }) + } + + deleteNote = () => { + const { noteToDelete } = this.state; + this.props.notesActions.deleteNote(noteToDelete); + this.closeModal(); + } -const NotesList = ({notes}) => { + closeModal = () => { + this.setState({ + showModal: false, + noteToDelete: null + }) + } + + updateNote = (note, data) => { + this.props.notesActions.updateNote(note, data); + } + + render() { + if (this.props.notes.size === 0) { + return ( + No notes yet. Add notes with the textarea below. + ); + } + + return ( +
- if (notes.size === 0) { - return ( - No notes yet. Add notes with the textarea below. + {this.props.notes.map((note) => + + )} + + + + Are you sure? + + + + + + + +
); } - return ( -
- {notes.map((note) => - - )} -
- ); }; NotesList.propTypes = { notes: PropTypes.instanceOf(Immutable.List).isRequired }; -export default NotesList; +function mapStateToProps(state, props) { + return props; +} + +function mapDispatchToProps(dispatch) { + return { + notesActions: bindActionCreators(notesActions, dispatch), + } +} + +export default connect(mapStateToProps, mapDispatchToProps)(NotesList);