Skip to content

Commit

Permalink
Refactoring Sidenav implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
minhducsun2002 committed May 11, 2019
1 parent 8d4b392 commit 7da2c99
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 22 deletions.
34 changes: 15 additions & 19 deletions src/app/sidenav/sidenav.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,34 +17,30 @@ class Sidenav extends Component {
open: false
};

toggleSidenav = this.toggle = this.toggle.bind(this);
toggleSidenav = this.toggle;
}

toggle() {
toggle = () => {
this.setState({
open: !this.state.open
});
}
};

renderItems() {
return this.props.pages.map((entry, index) => {
// mirroring onClick function
return (
<ListItem
component={Link}
to={entry.link}
onClick={entry.page.props.onClick}
button={entry.page.props.button}
key={`navigator_${index}`}>
{entry.page}
</ListItem>
);
});
}
render() {
return (
<Drawer anchor='left' {...this.props} open={this.state.open} onClose={this.toggle}>
<List>{this.renderItems()}</List>
<List>
{this.props.children.map(({ link, page }, index) => (
<ListItem
component={Link}
to={link}
onClick={page.props.onClick}
button={page.props.button}
key={`navigator_${index}`}>
{page}
</ListItem>
))}
</List>
</Drawer>
);
}
Expand Down
6 changes: 3 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ class Hestia extends React.Component {
/>
<div style={{ display: this.state.user.loggedIn ? 'block' : 'none' }}>
<div>
<Sidenav
pages={[
<Sidenav>
{[
{
page: <HomepageLauncher button onClick={toggleSidenav} />,
link: '/'
Expand All @@ -128,7 +128,7 @@ class Hestia extends React.Component {
link: '/scoreboard'
}
]}
/>
</Sidenav>
<Route
path='/'
render={() => {
Expand Down

0 comments on commit 7da2c99

Please sign in to comment.