client/src/components/Sessions.js
changeset 12 48ddaa42b810
child 29 4cfeabef7d5e
equal deleted inserted replaced
11:6fb4de54acea 12:48ddaa42b810
       
     1 import React, { Component } from 'react';
       
     2 import { connect } from 'react-redux';
       
     3 import { bindActionCreators } from 'redux';
       
     4 import { Grid, Row, Col, ListGroup, ListGroupItem, Button } from 'react-bootstrap';
       
     5 import moment from 'moment';
       
     6 import '../App.css';
       
     7 import Navbar from './Navbar';
       
     8 import * as sessionsActions from '../actions/sessionsActions';
       
     9 
       
    10 class Sessions extends Component {
       
    11 
       
    12   createNewSession = () => {
       
    13     const result = this.props.actions.createNewSession();
       
    14     // FIXME Feels ugly, change location after state has changed?
       
    15     this.props.history.push('/sessions/' + result.session.id)
       
    16   }
       
    17 
       
    18   render() {
       
    19     return (
       
    20       <div>
       
    21         <Navbar history={this.props.history} />
       
    22         <Grid fluid>
       
    23           <Row>
       
    24             <Col md={6} mdOffset={3}>
       
    25               <ListGroup>
       
    26                 {this.props.sessions.map((session) =>
       
    27                   <ListGroupItem
       
    28                     key={session.id}
       
    29                     onClick={() => this.props.history.push('/sessions/' + session.id)}>
       
    30                     {session.title || 'No title'} {session.id} {moment(session.date).format('DD/MM/YYYY')}
       
    31                   </ListGroupItem>
       
    32                 )}
       
    33               </ListGroup>
       
    34               <Button bsStyle="success" onClick={this.createNewSession}>Create new session</Button>
       
    35             </Col>
       
    36           </Row>
       
    37         </Grid>
       
    38       </div>
       
    39     );
       
    40   }
       
    41 }
       
    42 
       
    43 function mapStateToProps(state, props) {
       
    44   return {
       
    45     currentSession: state.get('currentSession'),
       
    46     sessions: state.get('sessions')
       
    47   };
       
    48 }
       
    49 
       
    50 function mapDispatchToProps(dispatch) {
       
    51   return {
       
    52     actions: bindActionCreators(sessionsActions, dispatch)
       
    53   }
       
    54 }
       
    55 
       
    56 export default connect(mapStateToProps, mapDispatchToProps)(Sessions);