| author | ymh <ymh.work@gmail.com> |
| Thu, 03 Aug 2017 19:12:25 +0200 | |
| changeset 136 | 1a3be12af395 |
| parent 133 | 6f3078f7fd47 |
| child 137 | 279e1dffa213 |
| 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'; |
|
129
d48946d164c6
Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents:
124
diff
changeset
|
10 |
import { ActionEnum } from '../constants'; |
|
62
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
11 |
|
|
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
12 |
class SessionList extends Component { |
|
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
13 |
|
|
95
7bc08467c726
Add confirmation when deleting session.
Alexandre Segura <mex.zktk@gmail.com>
parents:
93
diff
changeset
|
14 |
state = { |
|
7bc08467c726
Add confirmation when deleting session.
Alexandre Segura <mex.zktk@gmail.com>
parents:
93
diff
changeset
|
15 |
showModal: false, |
|
7bc08467c726
Add confirmation when deleting session.
Alexandre Segura <mex.zktk@gmail.com>
parents:
93
diff
changeset
|
16 |
sessionToDelete: null |
|
7bc08467c726
Add confirmation when deleting session.
Alexandre Segura <mex.zktk@gmail.com>
parents:
93
diff
changeset
|
17 |
} |
|
7bc08467c726
Add confirmation when deleting session.
Alexandre Segura <mex.zktk@gmail.com>
parents:
93
diff
changeset
|
18 |
|
|
62
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
19 |
createSession = () => { |
|
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
20 |
const sessionId = uuidV1(); |
|
133
6f3078f7fd47
Work on correct protocol propagation
ymh <ymh.work@gmail.com>
parents:
129
diff
changeset
|
21 |
const groupName = (this.props.currentUser)?this.props.currentUser.get('default_group'):null; |
|
6f3078f7fd47
Work on correct protocol propagation
ymh <ymh.work@gmail.com>
parents:
129
diff
changeset
|
22 |
let protocol = null; |
|
6f3078f7fd47
Work on correct protocol propagation
ymh <ymh.work@gmail.com>
parents:
129
diff
changeset
|
23 |
if(groupName != null) { |
|
6f3078f7fd47
Work on correct protocol propagation
ymh <ymh.work@gmail.com>
parents:
129
diff
changeset
|
24 |
const group = this.props.groups.find((g) => g.name === groupName); |
|
6f3078f7fd47
Work on correct protocol propagation
ymh <ymh.work@gmail.com>
parents:
129
diff
changeset
|
25 |
if(group) { |
|
6f3078f7fd47
Work on correct protocol propagation
ymh <ymh.work@gmail.com>
parents:
129
diff
changeset
|
26 |
protocol = group.get('protocol'); |
|
6f3078f7fd47
Work on correct protocol propagation
ymh <ymh.work@gmail.com>
parents:
129
diff
changeset
|
27 |
} |
|
6f3078f7fd47
Work on correct protocol propagation
ymh <ymh.work@gmail.com>
parents:
129
diff
changeset
|
28 |
} |
|
6f3078f7fd47
Work on correct protocol propagation
ymh <ymh.work@gmail.com>
parents:
129
diff
changeset
|
29 |
this.props.sessionsActions.createSession(sessionId, groupName, protocol); |
|
62
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
30 |
this.props.history.push('/sessions/' + sessionId); |
|
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
31 |
} |
|
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
32 |
|
|
93
469da13402e2
Allow to delete session.
Alexandre Segura <mex.zktk@gmail.com>
parents:
62
diff
changeset
|
33 |
onClickDelete(session, e) { |
|
469da13402e2
Allow to delete session.
Alexandre Segura <mex.zktk@gmail.com>
parents:
62
diff
changeset
|
34 |
e.preventDefault(); |
|
469da13402e2
Allow to delete session.
Alexandre Segura <mex.zktk@gmail.com>
parents:
62
diff
changeset
|
35 |
e.stopPropagation(); |
|
469da13402e2
Allow to delete session.
Alexandre Segura <mex.zktk@gmail.com>
parents:
62
diff
changeset
|
36 |
|
|
95
7bc08467c726
Add confirmation when deleting session.
Alexandre Segura <mex.zktk@gmail.com>
parents:
93
diff
changeset
|
37 |
this.setState({ |
|
7bc08467c726
Add confirmation when deleting session.
Alexandre Segura <mex.zktk@gmail.com>
parents:
93
diff
changeset
|
38 |
showModal: true, |
|
7bc08467c726
Add confirmation when deleting session.
Alexandre Segura <mex.zktk@gmail.com>
parents:
93
diff
changeset
|
39 |
sessionToDelete: session |
|
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 |
} |
|
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 |
closeModal = () => { |
|
7bc08467c726
Add confirmation when deleting session.
Alexandre Segura <mex.zktk@gmail.com>
parents:
93
diff
changeset
|
44 |
this.setState({ showModal: false }) |
|
7bc08467c726
Add confirmation when deleting session.
Alexandre Segura <mex.zktk@gmail.com>
parents:
93
diff
changeset
|
45 |
} |
|
7bc08467c726
Add confirmation when deleting session.
Alexandre Segura <mex.zktk@gmail.com>
parents:
93
diff
changeset
|
46 |
|
|
7bc08467c726
Add confirmation when deleting session.
Alexandre Segura <mex.zktk@gmail.com>
parents:
93
diff
changeset
|
47 |
deleteSession = () => { |
|
7bc08467c726
Add confirmation when deleting session.
Alexandre Segura <mex.zktk@gmail.com>
parents:
93
diff
changeset
|
48 |
const { sessionToDelete } = this.state; |
|
7bc08467c726
Add confirmation when deleting session.
Alexandre Segura <mex.zktk@gmail.com>
parents:
93
diff
changeset
|
49 |
|
|
7bc08467c726
Add confirmation when deleting session.
Alexandre Segura <mex.zktk@gmail.com>
parents:
93
diff
changeset
|
50 |
this.props.sessionsActions.deleteSession(sessionToDelete); |
|
7bc08467c726
Add confirmation when deleting session.
Alexandre Segura <mex.zktk@gmail.com>
parents:
93
diff
changeset
|
51 |
|
|
7bc08467c726
Add confirmation when deleting session.
Alexandre Segura <mex.zktk@gmail.com>
parents:
93
diff
changeset
|
52 |
this.setState({ |
|
7bc08467c726
Add confirmation when deleting session.
Alexandre Segura <mex.zktk@gmail.com>
parents:
93
diff
changeset
|
53 |
showModal: false, |
|
7bc08467c726
Add confirmation when deleting session.
Alexandre Segura <mex.zktk@gmail.com>
parents:
93
diff
changeset
|
54 |
sessionToDelete: null |
|
7bc08467c726
Add confirmation when deleting session.
Alexandre Segura <mex.zktk@gmail.com>
parents:
93
diff
changeset
|
55 |
}) |
|
93
469da13402e2
Allow to delete session.
Alexandre Segura <mex.zktk@gmail.com>
parents:
62
diff
changeset
|
56 |
} |
|
469da13402e2
Allow to delete session.
Alexandre Segura <mex.zktk@gmail.com>
parents:
62
diff
changeset
|
57 |
|
|
62
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
58 |
render() { |
|
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
59 |
return ( |
|
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
60 |
<div> |
|
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
61 |
<Navbar history={this.props.history} /> |
|
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
62 |
<Grid fluid> |
|
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
63 |
<Row> |
|
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
64 |
<Col md={6} mdOffset={3}> |
|
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
65 |
<ListGroup> |
|
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
66 |
{this.props.sessions.map((session) => |
|
124
c77570164050
implement soft delete and indicator that session and notes have been modiied
ymh <ymh.work@gmail.com>
parents:
95
diff
changeset
|
67 |
<ListGroupItem key={session.get('_id')}> |
|
c77570164050
implement soft delete and indicator that session and notes have been modiied
ymh <ymh.work@gmail.com>
parents:
95
diff
changeset
|
68 |
<span onClick={() => this.props.history.push('/sessions/' + session.get('_id'))}>{session.title || 'No title'} {session.get('_id')} {moment(session.get('date')).format('DD/MM/YYYY')}</span> |
|
93
469da13402e2
Allow to delete session.
Alexandre Segura <mex.zktk@gmail.com>
parents:
62
diff
changeset
|
69 |
<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
|
70 |
<span className="material-icons">delete</span> |
|
469da13402e2
Allow to delete session.
Alexandre Segura <mex.zktk@gmail.com>
parents:
62
diff
changeset
|
71 |
</a> |
|
62
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
72 |
</ListGroupItem> |
|
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
73 |
)} |
|
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
74 |
</ListGroup> |
|
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
75 |
<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
|
76 |
</Col> |
|
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
77 |
</Row> |
|
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
78 |
</Grid> |
|
95
7bc08467c726
Add confirmation when deleting session.
Alexandre Segura <mex.zktk@gmail.com>
parents:
93
diff
changeset
|
79 |
|
|
7bc08467c726
Add confirmation when deleting session.
Alexandre Segura <mex.zktk@gmail.com>
parents:
93
diff
changeset
|
80 |
<Modal show={ this.state.showModal } onHide={ this.closeModal }> |
|
7bc08467c726
Add confirmation when deleting session.
Alexandre Segura <mex.zktk@gmail.com>
parents:
93
diff
changeset
|
81 |
<Modal.Body> |
|
7bc08467c726
Add confirmation when deleting session.
Alexandre Segura <mex.zktk@gmail.com>
parents:
93
diff
changeset
|
82 |
Are you sure? |
|
7bc08467c726
Add confirmation when deleting session.
Alexandre Segura <mex.zktk@gmail.com>
parents:
93
diff
changeset
|
83 |
</Modal.Body> |
|
7bc08467c726
Add confirmation when deleting session.
Alexandre Segura <mex.zktk@gmail.com>
parents:
93
diff
changeset
|
84 |
<Modal.Footer> |
|
7bc08467c726
Add confirmation when deleting session.
Alexandre Segura <mex.zktk@gmail.com>
parents:
93
diff
changeset
|
85 |
<Button bsStyle="primary" onClick={ this.deleteSession }>Confirm</Button> |
|
7bc08467c726
Add confirmation when deleting session.
Alexandre Segura <mex.zktk@gmail.com>
parents:
93
diff
changeset
|
86 |
<Button onClick={ this.closeModal }>Close</Button> |
|
7bc08467c726
Add confirmation when deleting session.
Alexandre Segura <mex.zktk@gmail.com>
parents:
93
diff
changeset
|
87 |
</Modal.Footer> |
|
7bc08467c726
Add confirmation when deleting session.
Alexandre Segura <mex.zktk@gmail.com>
parents:
93
diff
changeset
|
88 |
</Modal> |
|
7bc08467c726
Add confirmation when deleting session.
Alexandre Segura <mex.zktk@gmail.com>
parents:
93
diff
changeset
|
89 |
|
|
62
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
90 |
</div> |
|
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 |
|
|
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
95 |
function mapStateToProps(state, props) { |
|
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
96 |
return { |
|
133
6f3078f7fd47
Work on correct protocol propagation
ymh <ymh.work@gmail.com>
parents:
129
diff
changeset
|
97 |
sessions: state.get('sessions').filter(session => session.get('action') !== ActionEnum.DELETED), |
|
6f3078f7fd47
Work on correct protocol propagation
ymh <ymh.work@gmail.com>
parents:
129
diff
changeset
|
98 |
currentUser: state.getIn(['authStatus', 'currentUser']), |
|
6f3078f7fd47
Work on correct protocol propagation
ymh <ymh.work@gmail.com>
parents:
129
diff
changeset
|
99 |
groups: state.get('groups') |
|
62
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
100 |
}; |
|
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
101 |
} |
|
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
102 |
|
|
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
103 |
function mapDispatchToProps(dispatch) { |
|
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
104 |
return { |
|
133
6f3078f7fd47
Work on correct protocol propagation
ymh <ymh.work@gmail.com>
parents:
129
diff
changeset
|
105 |
sessionsActions: bindActionCreators(sessionsActions, dispatch), |
|
62
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
106 |
} |
|
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
107 |
} |
|
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
108 |
|
|
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
109 |
export default connect(mapStateToProps, mapDispatchToProps)(SessionList); |