Skip to content

Commit 53b627f

Browse files
committed
I put Menu in charge to know which links will be used
1 parent 0e44015 commit 53b627f

File tree

2 files changed

+30
-17
lines changed

2 files changed

+30
-17
lines changed

app/components/LinksApp/LinksApp.js

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,17 @@
11
import React from 'react';
2-
import { Router, Link } from 'react-router'
2+
import { Link } from 'react-router'
33

44
class LinksApp extends React.Component
55
{
66
constructor(props, context) {
77
super(props, context);
88
this.generate = this.generate.bind(this);
9-
this.handleLogout = this.handleLogout.bind(this);
109
this.handleClick = this.handleClick.bind(this);
1110
this.state = {
12-
links: [
13-
[ '/', 'Home'],
14-
['/client', 'Client'],
15-
['/area', 'Area']
16-
]
11+
links: this.props.links || []
1712
};
1813
}
1914

20-
handleLogout() {
21-
delete localStorage.token;
22-
this.context.router.push("/");
23-
}
24-
2515
handleClick(e) {
2616
if (this.context.onClick) {
2717
this.context.onClick();
@@ -46,16 +36,16 @@ class LinksApp extends React.Component
4636
return (
4737
<span className="nav-right nav-menu is-active">
4838
{this.generate()}
49-
<span className="nav-item">
50-
<a className="button" onClick={this.handleLogout}>Logout</a>
51-
</span>
5239
</span>
5340
);
5441
}
5542
}
5643

44+
LinksApp.propTypes = {
45+
links: React.PropTypes.array.isRequired
46+
};
47+
5748
LinksApp.contextTypes = {
58-
router: React.PropTypes.object.isRequired,
5949
onClick: React.PropTypes.func
6050
};
6151

app/components/Menu/Menu.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React from 'react';
2+
import { Router } from 'react-router'
23

34
import Nav from 'components/Nav/Nav'
45
import LinksApp from 'components/LinksApp/LinksApp'
@@ -7,13 +8,31 @@ import LinksApp from 'components/LinksApp/LinksApp'
78
class Menu extends React.Component{
89
constructor(props, context) {
910
super(props, context);
11+
this.handleLogout = this.handleLogout.bind(this);
1012
this.handleView = this.handleView.bind(this);
13+
this.state = {
14+
links: [
15+
[ '/', 'Home'],
16+
['/client', 'Client'],
17+
['/area', 'Area']
18+
]
19+
};
20+
}
21+
22+
handleLogout() {
23+
delete localStorage.token;
24+
this.context.router.push("/");
1125
}
1226

1327
handleView() {
1428
return (
1529
<Nav>
16-
<LinksApp />
30+
<LinksApp
31+
links={this.state.links}
32+
/>
33+
<span className="nav-item">
34+
<a className="button" onClick={this.handleLogout}>Logout</a>
35+
</span>
1736
</Nav>
1837
);
1938
}
@@ -30,5 +49,9 @@ class Menu extends React.Component{
3049
}
3150
}
3251

52+
Menu.contextTypes = {
53+
router: React.PropTypes.object.isRequired
54+
};
55+
3356
export default Menu;
3457

0 commit comments

Comments
 (0)