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> {
|
|
|
|
|
|
|
|
constructor(props, context) {
|
|
|
|
super(props, context);
|
2019-03-23 01:42:57 +00:00
|
|
|
this.state = {isLoggedIn: UserService.Instance.loggedIn};
|
|
|
|
|
|
|
|
// 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">
|
|
|
|
<a class="navbar-brand" href="#">rrf</a>
|
|
|
|
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
|
|
|
|
<span class="navbar-toggler-icon"></span>
|
|
|
|
</button>
|
|
|
|
<div class="collapse navbar-collapse">
|
|
|
|
<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">
|
|
|
|
<a class="nav-link" href={repoUrl}>Forums</a>
|
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-03-23 01:42:57 +00:00
|
|
|
handleLogoutClick(i: Navbar, event) {
|
|
|
|
UserService.Instance.logout();
|
2019-03-26 18:00:18 +00:00
|
|
|
// i.props.history.push('/');
|
2019-03-23 01:42:57 +00:00
|
|
|
}
|
2019-03-21 01:22:31 +00:00
|
|
|
}
|