| author | Alexandre Segura <mex.zktk@gmail.com> |
| Thu, 29 Jun 2017 17:02:21 +0200 | |
| changeset 107 | e6f85e26b08c |
| parent 95 | 7bc08467c726 |
| child 124 | c77570164050 |
| permissions | -rw-r--r-- |
|
62
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
1 |
import React, { Component } from 'react'; |
|
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
2 |
import { connect } from 'react-redux'; |
|
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
3 |
import { bindActionCreators } from 'redux'; |
|
95
7bc08467c726
Add confirmation when deleting session.
Alexandre Segura <mex.zktk@gmail.com>
parents:
93
diff
changeset
|
4 |
import { Grid, Row, Col, ListGroup, ListGroupItem, Button, Modal } from 'react-bootstrap'; |
|
62
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
5 |
import moment from 'moment'; |
|
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
6 |
import '../App.css'; |
|
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
7 |
import Navbar from './Navbar'; |
|
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
8 |
import * as sessionsActions from '../actions/sessionsActions'; |
|
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
9 |
import uuidV1 from 'uuid/v1'; |
|
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
10 |
|
|
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
11 |
class SessionList extends Component { |
|
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
12 |
|
|
95
7bc08467c726
Add confirmation when deleting session.
Alexandre Segura <mex.zktk@gmail.com>
parents:
93
diff
changeset
|
13 |
state = { |
|
7bc08467c726
Add confirmation when deleting session.
Alexandre Segura <mex.zktk@gmail.com>
parents:
93
diff
changeset
|
14 |
showModal: false, |
|
7bc08467c726
Add confirmation when deleting session.
Alexandre Segura <mex.zktk@gmail.com>
parents:
93
diff
changeset
|
15 |
sessionToDelete: null |
|
7bc08467c726
Add confirmation when deleting session.
Alexandre Segura <mex.zktk@gmail.com>
parents:
93
diff
changeset
|
16 |
} |
|
7bc08467c726
Add confirmation when deleting session.
Alexandre Segura <mex.zktk@gmail.com>
parents:
93
diff
changeset
|
17 |
|
|
62
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
18 |
createSession = () => { |
|
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
19 |
const sessionId = uuidV1(); |
|
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
20 |
this.props.sessionsActions.createSession(sessionId); |
|
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
21 |
this.props.history.push('/sessions/' + sessionId); |
|
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
22 |
} |
|
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
23 |
|
|
93
469da13402e2
Allow to delete session.
Alexandre Segura <mex.zktk@gmail.com>
parents:
62
diff
changeset
|
24 |
onClickDelete(session, e) { |
|
469da13402e2
Allow to delete session.
Alexandre Segura <mex.zktk@gmail.com>
parents:
62
diff
changeset
|
25 |
e.preventDefault(); |
|
469da13402e2
Allow to delete session.
Alexandre Segura <mex.zktk@gmail.com>
parents:
62
diff
changeset
|
26 |
e.stopPropagation(); |
|
469da13402e2
Allow to delete session.
Alexandre Segura <mex.zktk@gmail.com>
parents:
62
diff
changeset
|
27 |
|
|
95
7bc08467c726
Add confirmation when deleting session.
Alexandre Segura <mex.zktk@gmail.com>
parents:
93
diff
changeset
|
28 |
this.setState({ |
|
7bc08467c726
Add confirmation when deleting session.
Alexandre Segura <mex.zktk@gmail.com>
parents:
93
diff
changeset
|
29 |
showModal: true, |
|
7bc08467c726
Add confirmation when deleting session.
Alexandre Segura <mex.zktk@gmail.com>
parents:
93
diff
changeset
|
30 |
sessionToDelete: session |
|
7bc08467c726
Add confirmation when deleting session.
Alexandre Segura <mex.zktk@gmail.com>
parents:
93
diff
changeset
|
31 |
}) |
|
7bc08467c726
Add confirmation when deleting session.
Alexandre Segura <mex.zktk@gmail.com>
parents:
93
diff
changeset
|
32 |
} |
|
7bc08467c726
Add confirmation when deleting session.
Alexandre Segura <mex.zktk@gmail.com>
parents:
93
diff
changeset
|
33 |
|
|
7bc08467c726
Add confirmation when deleting session.
Alexandre Segura <mex.zktk@gmail.com>
parents:
93
diff
changeset
|
34 |
closeModal = () => { |
|
7bc08467c726
Add confirmation when deleting session.
Alexandre Segura <mex.zktk@gmail.com>
parents:
93
diff
changeset
|
35 |
this.setState({ showModal: false }) |
|
7bc08467c726
Add confirmation when deleting session.
Alexandre Segura <mex.zktk@gmail.com>
parents:
93
diff
changeset
|
36 |
} |
|
7bc08467c726
Add confirmation when deleting session.
Alexandre Segura <mex.zktk@gmail.com>
parents:
93
diff
changeset
|
37 |
|
|
7bc08467c726
Add confirmation when deleting session.
Alexandre Segura <mex.zktk@gmail.com>
parents:
93
diff
changeset
|
38 |
deleteSession = () => { |
|
7bc08467c726
Add confirmation when deleting session.
Alexandre Segura <mex.zktk@gmail.com>
parents:
93
diff
changeset
|
39 |
const { sessionToDelete } = this.state; |
|
7bc08467c726
Add confirmation when deleting session.
Alexandre Segura <mex.zktk@gmail.com>
parents:
93
diff
changeset
|
40 |
|
|
7bc08467c726
Add confirmation when deleting session.
Alexandre Segura <mex.zktk@gmail.com>
parents:
93
diff
changeset
|
41 |
this.props.sessionsActions.deleteSession(sessionToDelete); |
|
7bc08467c726
Add confirmation when deleting session.
Alexandre Segura <mex.zktk@gmail.com>
parents:
93
diff
changeset
|
42 |
|
|
7bc08467c726
Add confirmation when deleting session.
Alexandre Segura <mex.zktk@gmail.com>
parents:
93
diff
changeset
|
43 |
this.setState({ |
|
7bc08467c726
Add confirmation when deleting session.
Alexandre Segura <mex.zktk@gmail.com>
parents:
93
diff
changeset
|
44 |
showModal: false, |
|
7bc08467c726
Add confirmation when deleting session.
Alexandre Segura <mex.zktk@gmail.com>
parents:
93
diff
changeset
|
45 |
sessionToDelete: null |
|
7bc08467c726
Add confirmation when deleting session.
Alexandre Segura <mex.zktk@gmail.com>
parents:
93
diff
changeset
|
46 |
}) |
|
93
469da13402e2
Allow to delete session.
Alexandre Segura <mex.zktk@gmail.com>
parents:
62
diff
changeset
|
47 |
} |
|
469da13402e2
Allow to delete session.
Alexandre Segura <mex.zktk@gmail.com>
parents:
62
diff
changeset
|
48 |
|
|
62
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
49 |
render() { |
|
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
50 |
return ( |
|
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
51 |
<div> |
|
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
52 |
<Navbar history={this.props.history} /> |
|
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
53 |
<Grid fluid> |
|
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
54 |
<Row> |
|
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
55 |
<Col md={6} mdOffset={3}> |
|
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
56 |
<ListGroup> |
|
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
57 |
{this.props.sessions.map((session) => |
|
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
58 |
<ListGroupItem |
|
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
59 |
key={session.get('_id')} |
|
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
60 |
onClick={() => this.props.history.push('/sessions/' + session.get('_id'))}> |
|
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
61 |
{session.title || 'No title'} {session.get('_id')} {moment(session.get('date')).format('DD/MM/YYYY')} |
|
93
469da13402e2
Allow to delete session.
Alexandre Segura <mex.zktk@gmail.com>
parents:
62
diff
changeset
|
62 |
<a className="pull-right" onClick={ this.onClickDelete.bind(this, session) }> |
|
469da13402e2
Allow to delete session.
Alexandre Segura <mex.zktk@gmail.com>
parents:
62
diff
changeset
|
63 |
<span className="material-icons">delete</span> |
|
469da13402e2
Allow to delete session.
Alexandre Segura <mex.zktk@gmail.com>
parents:
62
diff
changeset
|
64 |
</a> |
|
62
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
65 |
</ListGroupItem> |
|
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
66 |
)} |
|
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
67 |
</ListGroup> |
|
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
68 |
<Button bsStyle="success" onClick={this.createSession}>Create new session</Button> |
|
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
69 |
</Col> |
|
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
70 |
</Row> |
|
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
71 |
</Grid> |
|
95
7bc08467c726
Add confirmation when deleting session.
Alexandre Segura <mex.zktk@gmail.com>
parents:
93
diff
changeset
|
72 |
|
|
7bc08467c726
Add confirmation when deleting session.
Alexandre Segura <mex.zktk@gmail.com>
parents:
93
diff
changeset
|
73 |
<Modal show={ this.state.showModal } onHide={ this.closeModal }> |
|
7bc08467c726
Add confirmation when deleting session.
Alexandre Segura <mex.zktk@gmail.com>
parents:
93
diff
changeset
|
74 |
<Modal.Body> |
|
7bc08467c726
Add confirmation when deleting session.
Alexandre Segura <mex.zktk@gmail.com>
parents:
93
diff
changeset
|
75 |
Are you sure? |
|
7bc08467c726
Add confirmation when deleting session.
Alexandre Segura <mex.zktk@gmail.com>
parents:
93
diff
changeset
|
76 |
</Modal.Body> |
|
7bc08467c726
Add confirmation when deleting session.
Alexandre Segura <mex.zktk@gmail.com>
parents:
93
diff
changeset
|
77 |
<Modal.Footer> |
|
7bc08467c726
Add confirmation when deleting session.
Alexandre Segura <mex.zktk@gmail.com>
parents:
93
diff
changeset
|
78 |
<Button bsStyle="primary" onClick={ this.deleteSession }>Confirm</Button> |
|
7bc08467c726
Add confirmation when deleting session.
Alexandre Segura <mex.zktk@gmail.com>
parents:
93
diff
changeset
|
79 |
<Button onClick={ this.closeModal }>Close</Button> |
|
7bc08467c726
Add confirmation when deleting session.
Alexandre Segura <mex.zktk@gmail.com>
parents:
93
diff
changeset
|
80 |
</Modal.Footer> |
|
7bc08467c726
Add confirmation when deleting session.
Alexandre Segura <mex.zktk@gmail.com>
parents:
93
diff
changeset
|
81 |
</Modal> |
|
7bc08467c726
Add confirmation when deleting session.
Alexandre Segura <mex.zktk@gmail.com>
parents:
93
diff
changeset
|
82 |
|
|
62
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
83 |
</div> |
|
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
84 |
); |
|
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
85 |
} |
|
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
86 |
} |
|
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
87 |
|
|
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
88 |
function mapStateToProps(state, props) { |
|
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
89 |
return { |
|
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
90 |
sessions: state['sessions'] |
|
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
91 |
}; |
|
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
92 |
} |
|
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
93 |
|
|
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
94 |
function mapDispatchToProps(dispatch) { |
|
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
95 |
return { |
|
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
96 |
sessionsActions: bindActionCreators(sessionsActions, dispatch) |
|
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
97 |
} |
|
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
98 |
} |
|
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
99 |
|
|
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
100 |
export default connect(mapStateToProps, mapDispatchToProps)(SessionList); |