180 lines
5.9 KiB
JavaScript
180 lines
5.9 KiB
JavaScript
|
/**
|
||
|
* Copyright (c) 2017 Tomek Wójcik <tomek@bthlabs.pl>
|
||
|
*
|
||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||
|
* of this software and associated documentation files (the "Software"), to
|
||
|
* deal in the Software without restriction, including without limitation the
|
||
|
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||
|
* sell copies of the Software, and to permit persons to whom the Software is
|
||
|
* furnished to do so, subject to the following conditions:
|
||
|
*
|
||
|
* The above copyright notice and this permission notice shall be included in
|
||
|
* all copies or substantial portions of the Software.
|
||
|
*
|
||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||
|
* IN THE SOFTWARE.
|
||
|
*/
|
||
|
|
||
|
import ClassNames from "classnames";
|
||
|
import ContainerComponent from "../components/ContainerComponent";
|
||
|
import Glyphicon from "react-bootstrap/lib/Glyphicon";
|
||
|
import React from "react";
|
||
|
import Navbar from "react-bootstrap/lib/Navbar";
|
||
|
import {Router, Link} from "react-router";
|
||
|
import reduxStore from "../store";
|
||
|
|
||
|
import {LAYOUT_WIDE} from "../lib/defs";
|
||
|
|
||
|
import AboutModalView from "./AboutModalView";
|
||
|
import SettingsModalView from "./SettingsModalView";
|
||
|
|
||
|
class NavigationBarItemView extends React.Component {
|
||
|
render () {
|
||
|
let className = ClassNames({
|
||
|
active: this.props.active
|
||
|
});
|
||
|
|
||
|
return (
|
||
|
<li className={className}>
|
||
|
<Link to={this.props.route} onClick={this.props.onClick}>
|
||
|
{this.props.title}
|
||
|
</Link>
|
||
|
</li>
|
||
|
);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
NavigationBarItemView.propTypes = {
|
||
|
active: React.PropTypes.bool,
|
||
|
route: React.PropTypes.string,
|
||
|
title: React.PropTypes.string,
|
||
|
onClick: React.PropTypes.func.isRequired
|
||
|
};
|
||
|
|
||
|
class NavigationBarView extends React.Component {
|
||
|
constructor (props) {
|
||
|
super(props);
|
||
|
this.onNavigationBarItemClick = this.onNavigationBarItemClick.bind(this);
|
||
|
this.onNavigationBarToggleExpanded = this.onNavigationBarToggleExpanded.bind(this);
|
||
|
this.onHideSettingsModal = this.onHideSettingsModal.bind(this);
|
||
|
this.onShowSettingsModalButtonClick = this.onShowSettingsModalButtonClick.bind(this);
|
||
|
this.onStoreChange = this.onStoreChange.bind(this);
|
||
|
this.onHideAboutModal = this.onHideAboutModal.bind(this);
|
||
|
this.onShowAboutModalButtonClick = this.onShowAboutModalButtonClick.bind(this);
|
||
|
|
||
|
this.state = {
|
||
|
layout: reduxStore.getState().settings.layout,
|
||
|
navBarExpanded: false,
|
||
|
showAboutModal: false,
|
||
|
showSettingsModal: false
|
||
|
};
|
||
|
}
|
||
|
componentDidMount () {
|
||
|
this._storeUnsubscribe = reduxStore.subscribe(this.onStoreChange);
|
||
|
}
|
||
|
componentWillUnmount () {
|
||
|
this._storeUnsubscribe();
|
||
|
}
|
||
|
onNavigationBarItemClick (e) {
|
||
|
this.setState({navBarExpanded: false});
|
||
|
}
|
||
|
onNavigationBarToggleExpanded (expanded) {
|
||
|
this.setState({navBarExpanded: expanded});
|
||
|
}
|
||
|
onHideSettingsModal () {
|
||
|
this.setState({showSettingsModal: false});
|
||
|
}
|
||
|
onShowSettingsModalButtonClick () {
|
||
|
this.setState({
|
||
|
navBarExpanded: false,
|
||
|
showSettingsModal: true
|
||
|
});
|
||
|
}
|
||
|
onStoreChange () {
|
||
|
this.setState({layout: reduxStore.getState().settings.layout});
|
||
|
}
|
||
|
onHideAboutModal () {
|
||
|
this.setState({showAboutModal: false});
|
||
|
}
|
||
|
onShowAboutModalButtonClick () {
|
||
|
this.setState({
|
||
|
navBarExpanded: false,
|
||
|
showAboutModal: true
|
||
|
});
|
||
|
}
|
||
|
render () {
|
||
|
return (
|
||
|
<div className="q3stats-navigation-bar">
|
||
|
<Navbar
|
||
|
ref="navbar"
|
||
|
collapseOnSelect
|
||
|
expanded={this.state.navBarExpanded}
|
||
|
fixedTop
|
||
|
fluid={this.state.layout == LAYOUT_WIDE}
|
||
|
onToggle={this.onNavigationBarToggleExpanded}>
|
||
|
<Navbar.Header>
|
||
|
<Navbar.Brand>
|
||
|
<a>Q3Stats</a>
|
||
|
</Navbar.Brand>
|
||
|
<Navbar.Toggle />
|
||
|
</Navbar.Header>
|
||
|
|
||
|
<Navbar.Collapse>
|
||
|
<ul className="nav navbar-nav">
|
||
|
<NavigationBarItemView
|
||
|
active={this.props.router.isActive("/", true)}
|
||
|
route="/"
|
||
|
title="Dashboard"
|
||
|
onClick={this.onNavigationBarItemClick} />
|
||
|
<NavigationBarItemView
|
||
|
active={this.props.router.isActive("/sessions/", false)}
|
||
|
route="/sessions/"
|
||
|
title="Sessions"
|
||
|
onClick={this.onNavigationBarItemClick} />
|
||
|
<NavigationBarItemView
|
||
|
active={this.props.router.isActive("/players/", false)}
|
||
|
route="/players/"
|
||
|
title="Players"
|
||
|
onClick={this.onNavigationBarItemClick} />
|
||
|
</ul>
|
||
|
|
||
|
<ul className="nav navbar-nav navbar-right">
|
||
|
<li>
|
||
|
<a onClick={this.onShowSettingsModalButtonClick}>
|
||
|
<Glyphicon className="hidden-xs hidden-sm" glyph="cog" />
|
||
|
<span className="hidden-md hidden-lg">Settings</span>
|
||
|
</a>
|
||
|
</li>
|
||
|
<li>
|
||
|
<a onClick={this.onShowAboutModalButtonClick}>
|
||
|
<Glyphicon className="hidden-xs hidden-sm" glyph="info-sign" />
|
||
|
<span className="hidden-md hidden-lg">About</span>
|
||
|
</a>
|
||
|
</li>
|
||
|
</ul>
|
||
|
</Navbar.Collapse>
|
||
|
</Navbar>
|
||
|
|
||
|
<SettingsModalView
|
||
|
show={this.state.showSettingsModal}
|
||
|
onHide={this.onHideSettingsModal} />
|
||
|
|
||
|
<AboutModalView
|
||
|
show={this.state.showAboutModal}
|
||
|
onHide={this.onHideAboutModal} />
|
||
|
</div>
|
||
|
);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
NavigationBarView.PropTypes = {
|
||
|
router: React.PropTypes.instanceOf(Router).isRequired
|
||
|
};
|
||
|
|
||
|
export default NavigationBarView;
|