@@ -8,12 +8,9 @@ import { connect } from 'react-redux';
8
8
import Styles from '../../Styles' ;
9
9
import Header from './Header' ;
10
10
import Sidebar from './Sidebar' ;
11
+ import { setSideBarIsOpen } from '../../actions' ;
11
12
12
13
class Main extends Component {
13
- state = {
14
- open : false ,
15
- } ;
16
-
17
14
static propTypes = {
18
15
classes : PropTypes . shape ( {
19
16
appBar : PropTypes . string . isRequired ,
@@ -42,6 +39,8 @@ class Main extends Component {
42
39
} ) ,
43
40
showSearch : PropTypes . bool ,
44
41
handleOnSearch : PropTypes . func ,
42
+ dispatchSetSideBarIsOpen : PropTypes . func . isRequired ,
43
+ open : PropTypes . bool ,
45
44
} ;
46
45
47
46
static defaultProps = {
@@ -50,14 +49,17 @@ class Main extends Component {
50
49
handleOnSearch : ( ) => { } ,
51
50
id : null ,
52
51
style : { } ,
52
+ open : false ,
53
53
} ;
54
54
55
55
handleDrawerOpen = ( ) => {
56
- this . setState ( { open : true } ) ;
56
+ const { dispatchSetSideBarIsOpen } = this . props ;
57
+ dispatchSetSideBarIsOpen ( true ) ;
57
58
} ;
58
59
59
60
handleDrawerClose = ( ) => {
60
- this . setState ( { open : false } ) ;
61
+ const { dispatchSetSideBarIsOpen } = this . props ;
62
+ dispatchSetSideBarIsOpen ( false ) ;
61
63
} ;
62
64
63
65
render ( ) {
@@ -69,8 +71,8 @@ class Main extends Component {
69
71
style,
70
72
showSearch,
71
73
handleOnSearch,
74
+ open,
72
75
} = this . props ;
73
- const { open } = this . state ;
74
76
75
77
return (
76
78
< div className = { classes . root } style = { style } >
@@ -102,11 +104,14 @@ class Main extends Component {
102
104
}
103
105
}
104
106
105
- const mapStateToProps = ( { authentication } ) => ( {
107
+ const mapStateToProps = ( { authentication, layout } ) => ( {
106
108
activity : Boolean ( authentication . getIn ( [ 'current' , 'activity' ] ) . size ) ,
109
+ open : layout . getIn ( [ 'sideBarState' , 'open' ] ) ,
107
110
} ) ;
108
111
109
- const mapDispatchToProps = { } ;
112
+ const mapDispatchToProps = {
113
+ dispatchSetSideBarIsOpen : setSideBarIsOpen ,
114
+ } ;
110
115
111
116
const ConnectedComponent = connect ( mapStateToProps , mapDispatchToProps ) ( Main ) ;
112
117
0 commit comments