@@ -52,16 +52,28 @@ const styles = theme => ({
52
52
53
53
const NavItem = withRouter ( ( { route, render, location, history } ) => render ( { selected : location . pathname === route , navigate : ( ) => history . push ( route ) } ) ) ;
54
54
55
- const DrawerMenuItem = withStyles ( styles , { withTheme : true } ) ( ( { onClick, selected, label, classes} ) => (
55
+ const DrawerItem = withStyles ( styles , { withTheme : true } ) ( ( { onClick, selected, label, classes } ) => (
56
56
< ListItem button onClick = { onClick } >
57
57
< ListItemText classes = { selected ? {
58
58
primary : classes . selectedItem
59
59
} : { } }
60
60
primary = { label } />
61
61
</ ListItem >
62
- ) )
62
+ ) ) ;
63
63
64
- class AppBarBase extends Component {
64
+ const DrawerNavItem = ( { route, label } ) => (
65
+ < NavItem route = { route } render = { ( { selected, navigate } ) => (
66
+ < DrawerItem selected = { selected } onClick = { navigate } label = { label } />
67
+ ) } />
68
+ ) ;
69
+
70
+ const TopMenuNavItem = ( { route, label } ) => (
71
+ < NavItem route = { route } render = { ( { selected, navigate } ) => (
72
+ < Button color = { selected ? 'secondary' : 'inherit' } onClick = { navigate } > { label } </ Button >
73
+ ) } />
74
+ )
75
+
76
+ class AppBar extends Component {
65
77
state = {
66
78
drawerOpen : false ,
67
79
anchorEl : null
@@ -79,7 +91,7 @@ class AppBarBase extends Component {
79
91
this . setState ( { anchorEl : null } ) ;
80
92
} ;
81
93
render ( ) {
82
- const { classes, auth, location , history } = this . props ;
94
+ const { classes, auth } = this . props ;
83
95
const { anchorEl } = this . state ;
84
96
const open = Boolean ( anchorEl ) ;
85
97
@@ -106,10 +118,10 @@ class AppBarBase extends Component {
106
118
{ auth && (
107
119
< div className = { classes . topToolbar } >
108
120
< div className = { classes . topMenu } >
109
- < Button color = { location . pathname === '/' ? 'secondary' : 'inherit' } onClick = { ( ) => history . push ( '/' ) } > Home </ Button >
110
- < Button color = { location . pathname === '/categories' ? 'secondary' : 'inherit' } onClick = { ( ) => history . push ( '/categories' ) } > Categorii </ Button >
111
- < Button color = { location . pathname === '/proposals' ? 'secondary' : 'inherit' } onClick = { ( ) => history . push ( '/proposals' ) } > Propuneri legislative</ Button >
112
- < Button color = { location . pathname === '/institutions' ? 'secondary' : 'inherit' } onClick = { ( ) => history . push ( '/institutions' ) } > Institutii </ Button >
121
+ < TopMenuNavItem route = '/' label = 'Home' / >
122
+ < TopMenuNavItem route = '/categories' label = 'Categorii' / >
123
+ < TopMenuNavItem route = '/proposals' label = ' Propuneri legislative' / >
124
+ < TopMenuNavItem route = '/institutions' label = 'Institutii' / >
113
125
</ div >
114
126
< Typography
115
127
variant = "body1"
@@ -152,18 +164,10 @@ class AppBarBase extends Component {
152
164
< NavDrawer open = { this . state . drawerOpen }
153
165
onClose = { this . handleDrawerToggle } >
154
166
< List >
155
- < NavItem route = '/' render = { ( { selected, navigate } ) => (
156
- < DrawerMenuItem selected = { selected } onClick = { navigate } label = 'Home' />
157
- ) } />
158
- < NavItem route = '/categories' render = { ( { selected, navigate } ) => (
159
- < DrawerMenuItem selected = { selected } onClick = { navigate } label = 'Categorii' />
160
- ) } />
161
- < NavItem route = '/proposals' render = { ( { selected, navigate } ) => (
162
- < DrawerMenuItem selected = { selected } onClick = { navigate } label = 'Propuneri legislative' />
163
- ) } />
164
- < NavItem route = '/institutions' render = { ( { selected, navigate } ) => (
165
- < DrawerMenuItem selected = { selected } onClick = { navigate } label = 'Institutii' />
166
- ) } />
167
+ < DrawerNavItem route = '/' label = 'Home' />
168
+ < DrawerNavItem route = '/categories' label = 'Categorii' />
169
+ < DrawerNavItem route = '/proposals' label = 'Propuneri legislative' />
170
+ < DrawerNavItem route = '/institutions' label = 'Institutii' />
167
171
</ List >
168
172
</ NavDrawer >
169
173
</ Hidden >
@@ -172,29 +176,11 @@ class AppBarBase extends Component {
172
176
}
173
177
}
174
178
175
- AppBarBase . propTypes = {
179
+ AppBar . propTypes = {
176
180
classes : PropTypes . object . isRequired ,
177
- auth : PropTypes . object ,
178
- match : PropTypes . object . isRequired ,
179
- location : PropTypes . object . isRequired ,
180
- history : PropTypes . object . isRequired
181
+ auth : PropTypes . object
181
182
} ;
182
183
183
-
184
- AppBarBase . defaultProps = {
185
- location : {
186
- pathname : '/'
187
- } ,
188
- history : {
189
- push : ( ) => { }
190
- }
191
- }
192
-
193
-
194
- const AppBar = withStyles ( styles , { withTheme : true } ) ( AppBarBase ) ;
195
-
196
- export { AppBar } ;
197
-
198
- export default withRouter ( AppBar ) ;
184
+ export default withStyles ( styles , { withTheme : true } ) ( AppBar ) ;
199
185
200
186
0 commit comments