client/src/components/Session.js
author ymh <ymh.work@gmail.com>
Mon, 19 Jun 2017 21:46:21 +0200
changeset 59 1eb52770eefa
parent 58 f16a080e0bc4
child 62 b2514a9bcd49
permissions -rw-r--r--
Backed out changeset f16a080e0bc4

import React, { Component } from 'react';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import { Grid, Row, Col } from 'react-bootstrap';
import '../App.css';
import Navbar from './Navbar';
import NoteInput from './NoteInput';
import NotesList from './NotesList';
import SessionForm from './SessionForm';
import * as sessionsActions from '../actions/sessionsActions';
import * as notesActions from '../actions/notesActions';

class Session extends Component {

  componentDidMount = () => {
    this.props.notesActions.loadNotesBySession({ _id: this.props.match.params.id });
  }

  render() {
    return (
      <div>
        <Navbar history={this.props.history} />
        <div className="session-container">
          <Grid fluid className="session-notes">
            <Row>
              <Col md={3}>
                <SessionForm session={this.props.currentSession} />
              </Col>
              <Col md={9}>
                <NotesList notes={this.props.notes} />
              </Col>
            </Row>
          </Grid>
          <section className="editor-fixed">
            <Grid fluid>
              <Row>
                <Col md={9} mdOffset={3}>
                  <NoteInput session={this.props.currentSession} addNote={this.props.notesActions.addNote} />
                </Col>
              </Row>
            </Grid>
          </section>
        </div>
      </div>
    );
  }
}

function mapStateToProps(state, props) {

  const sessionId = props.match.params.id;

  const sessions = state.get('sessions');
  const notes = state.get('notes');
  const currentSession = sessions.find(session => session._id === sessionId);

  return {
    currentSession,
    sessions,
    notes,
  };
}

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

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