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