client/src/components/NotesContainer.js
author ymh <ymh.work@gmail.com>
Tue, 23 May 2017 13:15:34 +0200
changeset 3 3b5d37d84cfe
parent 2 b52921a63e77
permissions -rw-r--r--
Some code rename and reorg + basic tests

import React, { Component } from 'react';
import {connect} from 'react-redux';
import {bindActionCreators} from 'redux';

import PropTypes from 'prop-types';
import Immutable from 'immutable';

import { Grid, Row, Col} from 'react-bootstrap';

import * as notesActions from '../actions/notesActions';
import NotesList from './NotesList';
import NoteInput from './NoteInput';

class NotesContainer extends Component {
    render() {
        const { notes } = this.props;
        return (
          <Grid>
            <Row>
              <Col xs={12} md={12}>
                <NotesList notes={notes} />
              </Col>
            </Row>
            <Row>
              <Col xs={12} md={12}>
                <NoteInput addNote={this.props.actions.addNote} />
              </Col>
            </Row>
          </Grid>
        );
    }
}

NotesContainer.propTypes = {
    notes: PropTypes.instanceOf(Immutable.List).isRequired,
    actions: PropTypes.object.isRequired
}

function mapStateToProps(state, props) {
  return {
    notes: state.get('notes')
  };
}

function mapDispatchToProps(dispatch) {
  return {
    actions: bindActionCreators(notesActions, dispatch)
  }
}


export default connect(mapStateToProps, mapDispatchToProps)(NotesContainer);