Skip to content

Commit 0eda333

Browse files
committed
Mise en place de la connexion entre reducers et action parles containers
1 parent fe8ab31 commit 0eda333

19 files changed

+275
-89
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"react": "^15.6.1",
88
"react-dom": "^15.6.1",
99
"react-redux": "^5.0.5",
10-
"react-router": "^4.1.2",
10+
"react-router": "3",
1111
"react-scripts": "1.0.10",
1212
"redux": "^3.7.2",
1313
"redux-thunk": "^2.2.0"

public/index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,7 @@
3636
To begin the development, run `npm start` or `yarn start`.
3737
To create a production bundle, use `npm run build` or `yarn build`.
3838
-->
39+
<script src='https://cdnjs.cloudflare.com/ajax/libs/react/15.3.1/react.min.js'></script>
40+
<script src='https://cdnjs.cloudflare.com/ajax/libs/react/15.3.1/react-dom.min.js'></script>
3941
</body>
4042
</html>

src/actions/index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22
import axios from 'axios';
33

44
//Liste des actions
5-
import * from '../constants/actionTypes';
5+
import {
6+
FETCH_INTERVENTIONS,FETCH_INTERVENTIONS_SUCCESS,FETCH_INTERVENTIONS_FAILURE,
7+
FETCH_COMPETENCES,FETCH_COMPETENCES_SUCCESS,FETCH_COMPETENCES_FAILURE
8+
} from '../constants/actionTypes';
69

710
// Point d'entré de notre API
8-
const ROOT_URI = 'http://localhost:3000';
11+
const ROOT_URI = 'http://127.0.0.1:8000';
912

1013
/*-------- Listes des action du domaine d'intervention -------------*/
1114

src/components/App.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React, { Component } from 'react';
2-
import logo from '../assets/img/logo.svg';
32
import '../assets/css/App.css';
43

54
class App extends Component {

src/components/competences.js

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import React, { Component } from 'react';
22
//import { Link } from 'react-router';
3+
import { connect } from 'react-redux';
4+
import * as actions from '../actions/index';
35

46
class Competences extends Component {
57

@@ -8,20 +10,19 @@ class Competences extends Component {
810
}
911

1012
renderCompetences(competences) {
11-
return competences.map((competence) => {
12-
return {
13-
<div>
14-
<h3>{competence.titre}</h3>
15-
<p>{competence.description}</p>
16-
</div>
17-
};
13+
return ((competence) => {
14+
return (
15+
<li key={competence.id}>
16+
<p>{competence.titre}</p>
17+
</li>
18+
);
1819
});
1920
}
2021

2122
render() {
22-
const { competences, error, loding } = this.props.competencesList;
23+
const { competences, error, loading } = `${this.props.competencesList}`;
2324

24-
if(loding) {
25+
if(loading) {
2526
return <div className="interventions">Loading...</div>
2627
}
2728
else if(error) {
@@ -30,10 +31,18 @@ class Competences extends Component {
3031
return (
3132
<div>
3233
<h2>Divers Competences</h2>
33-
{this.renderCompetences(competences)}
34+
<ul>
35+
{this.renderCompetences(competences)}
36+
</ul>
3437
</div>
3538
);
3639
}
3740
}
3841

39-
export default Competences;
42+
function mapStateToProps(state) {
43+
return{
44+
competencesList: state.competencesList
45+
}
46+
}
47+
48+
export default connect(mapStateToProps,actions)(Competences);

src/components/interventions.js

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,53 @@
1+
'use strict';
12
import React, { Component } from 'react';
23
//import { Link } from 'react-router';
4+
import {bindActionCreators} from 'redux';
5+
import { connect } from 'react-redux';
6+
7+
8+
import {fetchInterventions} from '../actions/index';
9+
10+
import {getInterventions} from '../reducers/intervention_reducer'
311

412
class Interventions extends Component {
513

6-
ComponentWillMount() {
7-
this.props.fetchInterventions();
14+
componentWillMount() {
15+
this.props.listActions;
816
}
917

10-
renderCompetences(interventions) {
11-
return interventions.map((intervention) => {
12-
return {
13-
<div>
14-
<h3>{intervention.nom}</h3>
15-
<p>{intervention.description}</p>
18+
renderInterventions(interventions) {
19+
interventions.map(interventions => {
20+
return (
21+
<div key={interventions.id}>
22+
<h3>{interventions.nom}</h3>
23+
<p>{interventions.description}</p>
1624
</div>
17-
};
25+
);
1826
});
1927
}
2028

2129
render() {
22-
const { interventions, error, loding } = this.props.interventionsList;
23-
24-
if(loding) {
25-
return <div className="interventions">Loading...</div>
26-
}
27-
else if(error) {
28-
return <div className="alert">Error : {error}</div>
29-
}
30+
const interventions = this.props.interventionsList;
31+
3032
return (
3133
<div>
32-
<h2>Divers Competences</h2>
34+
<h2>Divers Interventions</h2>
3335
{this.renderInterventions(interventions)}
3436
</div>
3537
);
38+
};
39+
}
40+
41+
function mapDispatchToProps(dispatch){
42+
return {
43+
listActions: bindActionCreators(fetchInterventions, dispatch)
44+
}
45+
}
46+
47+
function mapStateToProps(state) {
48+
return{
49+
interventionsList: state.getInterventions
3650
}
3751
}
3852

39-
export default Interventions;
53+
export default connect(mapStateToProps,mapDispatchToProps)(Interventions);

src/constants/actionTypes.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//Asyncrone request and Promise based HTTP client for the browser
2-
import axios from 'axios';
31

42
//Liste des Interventins
53
export const FETCH_INTERVENTIONS = 'FETCH_INTERVENTIONS';
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { connect } from 'react-redux';
2+
import * as actions from '../actions/index';
3+
4+
import Competences from '../components/Competences';
5+
6+
function mapStateToProps(state) {
7+
return{
8+
competencesList: state.competencesList
9+
}
10+
}
11+
12+
export default connect(mapStateToProps,actions)(Competences);
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { connect } from 'react-redux';
2+
import * as actions from '../actions/index';
3+
4+
import Interventions from '../components/Interventions';
5+
6+
function mapStateToProps(state) {
7+
return{
8+
interventionsList: state.interventionsList
9+
}
10+
}
11+
12+
export default connect(mapStateToProps,actions)(Interventions);

src/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import routes from './routes/index';
88

99
import { createStore, applyMiddleware } from 'redux';
1010
import thunk from 'redux-thunk';
11-
import reducers from './reducers';
11+
import reducers from './reducers/index';
12+
1213

1314
const createStoreWithMiddleware = applyMiddleware(thunk)(createStore);
1415
const store = createStoreWithMiddleware(reducers);

0 commit comments

Comments
 (0)