@@ -10,8 +10,7 @@ import DishDetail from './DishdetailComponent';
10
10
11
11
import { Switch , Route , Redirect , withRouter } from 'react-router-dom' ;
12
12
import { connect } from 'react-redux' ;
13
- import { addComment , fetchDishes } from '../redux/ActionCreators' ;
14
-
13
+ import { addComment , fetchDishes , fetchComments , fetchPromos } from '../redux/ActionCreators' ;
15
14
import { actions } from 'react-redux-form' ;
16
15
17
16
const mapStateToProps = state => {
@@ -25,12 +24,16 @@ const mapStateToProps = state => {
25
24
}
26
25
27
26
const mapDispatchToProps = ( dispatch ) => ( {
28
- addComment : ( dishId , rating , author , comment ) => dispatch ( addComment ( dishId , rating , author , comment ) ) ,
27
+ addComment : ( dishId , rating , author , comment ) => dispatch ( addComment ( dishId , rating , author , comment ) ) ,
29
28
fetchDishes : ( ) => { dispatch ( fetchDishes ( ) ) } ,
29
+ resetFeedbackForm : ( ) => { dispatch ( actions . reset ( 'feedback' ) ) } ,
30
30
31
- resetFeedbackForm : ( ) => {
32
- dispatch ( actions . reset ( 'feedback' ) )
33
- } ,
31
+ fetchComments : ( ) => dispatch ( fetchComments ( ) ) ,
32
+
33
+ fetchPromos : ( ) => dispatch ( fetchPromos ( ) )
34
+
35
+
36
+
34
37
} ) ;
35
38
36
39
@@ -42,23 +45,40 @@ class Main extends Component {
42
45
43
46
componentDidMount ( ) {
44
47
this . props . fetchDishes ( ) ;
48
+ this . props . fetchComments ( ) ;
49
+ this . props . fetchPromos ( ) ;
45
50
}
46
51
47
52
render ( ) {
48
53
54
+
55
+
56
+
57
+
58
+
49
59
const HomePage = ( ) => {
50
- return (
51
- < Home
52
- dish = { this . props . dishes . dishes . filter ( ( dish ) => dish . featured ) [ 0 ] }
60
+ return (
61
+ < Home
62
+ dish = { this . props . dishes . dishes . filter ( dish => dish . featured ) [ 0 ] }
53
63
dishesLoading = { this . props . dishes . isLoading }
54
- dishesErrMess = { this . props . dishes . errMess }
64
+ dishErrMess = { this . props . dishes . errMess }
65
+ promotion = {
66
+ this . props . promotions . promotions . filter ( promo => promo . featured ) [ 0 ]
67
+ }
68
+ promoLoading = { this . props . promotions . isLoading }
69
+ promoErrMess = { this . props . promotions . errMess }
70
+ leader = { this . props . leaders . filter ( ( leader ) => leader . featured ) [ 0 ] }
71
+
55
72
56
- promotion = { this . props . promotions . filter ( ( promotion ) => promotion . featured ) [ 0 ] }
57
- leader = { this . props . leaders . filter ( ( leader ) => leader . featured ) [ 0 ] }
58
73
/>
59
74
) ;
60
75
} ;
61
76
77
+
78
+
79
+
80
+
81
+
62
82
const AboutUsPage = ( ) => {
63
83
return (
64
84
< About
@@ -70,14 +90,13 @@ class Main extends Component {
70
90
71
91
const DishWithId = ( { match} ) => {
72
92
return (
73
- < DishDetail
74
- dish = { this . props . dishes . dishes . filter ( ( dish ) => dish . id === parseInt ( match . params . dishId , 10 ) ) [ 0 ] }
93
+ < DishDetail dish = { this . props . dishes . dishes . filter ( ( dish ) => dish . id === parseInt ( match . params . dishId , 10 ) ) [ 0 ] }
75
94
isLoading = { this . props . dishes . isLoading }
76
95
errMess = { this . props . dishes . errMess }
77
-
78
- comments = { this . props . comments . filter ( ( comment ) => comment . dishId === parseInt ( match . params . dishId , 10 ) ) }
96
+
97
+ comments = { this . props . comments . comments . filter ( ( comment ) => comment . dishId === parseInt ( match . params . dishId , 10 ) ) }
98
+ commentsErrMess = { this . props . comments . errMess }
79
99
addComment = { this . props . addComment }
80
-
81
100
/>
82
101
) ;
83
102
} ;
0 commit comments