2019-03-21 01:22:31 +00:00
|
|
|
import { Component, linkEvent } from 'inferno';
|
|
|
|
import { Link } from 'inferno-router';
|
|
|
|
import { repoUrl } from '../utils';
|
2019-03-23 01:42:57 +00:00
|
|
|
import { UserService } from '../services';
|
2019-03-21 01:22:31 +00:00
|
|
|
|
|
|
|
export class Navbar extends Component<any, any> {
|
|
|
|
|
2019-04-08 05:19:02 +00:00
|
|
|
constructor(props: any, context: any) {
|
2019-03-21 01:22:31 +00:00
|
|
|
super(props, context);
|
2019-04-06 22:49:51 +00:00
|
|
|
this.state = {isLoggedIn: UserService.Instance.loggedIn, expanded: false};
|
2019-03-23 01:42:57 +00:00
|
|
|
|
|
|
|
// Subscribe to user changes
|
|
|
|
UserService.Instance.sub.subscribe(user => {
|
|
|
|
let loggedIn: boolean = user !== null;
|
|
|
|
this.setState({isLoggedIn: loggedIn});
|
|
|
|
});
|
2019-03-21 01:22:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
2019-03-23 01:42:57 +00:00
|
|
|
<div>{this.navbar()}</div>
|
2019-03-21 01:22:31 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO class active corresponding to current page
|
2019-03-23 01:42:57 +00:00
|
|
|
// TODO toggle css collapse
|
2019-03-21 01:22:31 +00:00
|
|
|
navbar() {
|
|
|
|
return (
|
2019-03-23 01:42:57 +00:00
|
|
|
<nav class="navbar navbar-expand-sm navbar-light bg-light p-0 px-3 shadow">
|
2019-04-06 22:49:51 +00:00
|
|
|
<a class="navbar-brand" href="#">
|
|
|
|
<svg class="icon mr-2"><use xlinkHref="#icon-mouse"></use></svg>
|
|
|
|
Lemmy
|
|
|
|
</a>
|
|
|
|
<button class="navbar-toggler" type="button" onClick={linkEvent(this, this.expandNavbar)}>
|
2019-03-23 01:42:57 +00:00
|
|
|
<span class="navbar-toggler-icon"></span>
|
|
|
|
</button>
|
2019-04-06 22:49:51 +00:00
|
|
|
<div className={`${!this.state.expanded && 'collapse'} navbar-collapse`}>
|
2019-03-23 01:42:57 +00:00
|
|
|
<ul class="navbar-nav mr-auto">
|
|
|
|
<li class="nav-item">
|
2019-04-03 06:49:32 +00:00
|
|
|
<a class="nav-link" href={repoUrl}>About</a>
|
|
|
|
</li>
|
|
|
|
<li class="nav-item">
|
2019-04-04 20:00:19 +00:00
|
|
|
<Link class="nav-link" to="/communities">Forums</Link>
|
2019-03-23 01:42:57 +00:00
|
|
|
</li>
|
|
|
|
<li class="nav-item">
|
|
|
|
<Link class="nav-link" to="/create_post">Create Post</Link>
|
|
|
|
</li>
|
|
|
|
<li class="nav-item">
|
|
|
|
<Link class="nav-link" to="/create_community">Create Forum</Link>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
<ul class="navbar-nav ml-auto mr-2">
|
|
|
|
<li class="nav-item">
|
|
|
|
{this.state.isLoggedIn ?
|
|
|
|
<a role="button" class="nav-link pointer" onClick={ linkEvent(this, this.handleLogoutClick) }>Logout</a> :
|
|
|
|
<Link class="nav-link" to="/login">Login</Link>
|
|
|
|
}
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
2019-03-21 01:22:31 +00:00
|
|
|
</nav>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-04-08 05:19:02 +00:00
|
|
|
handleLogoutClick() {
|
2019-03-23 01:42:57 +00:00
|
|
|
UserService.Instance.logout();
|
|
|
|
}
|
2019-04-06 22:49:51 +00:00
|
|
|
|
2019-04-08 05:19:02 +00:00
|
|
|
expandNavbar(i: Navbar) {
|
2019-04-06 22:49:51 +00:00
|
|
|
i.state.expanded = !i.state.expanded;
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
2019-03-21 01:22:31 +00:00
|
|
|
}
|