Skip to content

Commit 8c35104

Browse files
committed
add hotkeys for planet switching
1 parent bea9dfd commit 8c35104

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

browser/main/Components/UserNavigator.jsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ module.exports = React.createClass({
2121
},
2222
componentDidMount: function () {
2323
this.unsubscribe = AuthStore.listen(this.onLogout)
24+
document.addEventListener('keydown', this.handleKeyDown)
2425
},
2526
componentWillUnmount: function () {
2627
this.unsubscribe()
28+
document.removeEventListener('keydown', this.handleKeyDown)
2729
},
2830
onLogout: function () {
2931
this.transitionTo('login')
@@ -40,11 +42,20 @@ module.exports = React.createClass({
4042
closePlanetCreateModal: function () {
4143
this.setState({isPlanetCreateModalOpen: false})
4244
},
45+
handleKeyDown: function (e) {
46+
if (e.metaKey && e.keyCode > 48 && e.keyCode < 58) {
47+
var planet = this.props.currentUser.Planets[e.keyCode - 49]
48+
if (planet != null) {
49+
this.transitionTo('planet', {userName: planet.userName, planetName: planet.name})
50+
}
51+
}
52+
e.preventDefault()
53+
},
4354
render: function () {
4455
var planets = this.props.currentUser.Planets.map(function (planet, index) {
4556
return (
4657
<li key={planet.id} className={this.props.currentPlanet != null && this.props.currentPlanet.name === planet.name ? 'active' : ''}>
47-
<Link to='planet' params={{userName: planet.userName, planetName: planet.name}} href>
58+
<Link to='planet' params={{userName: planet.userName, planetName: planet.name}}>
4859
{planet.name[0]}
4960
<div className='planetTooltip'>{planet.userName}/{planet.name}</div>
5061
</Link>

0 commit comments

Comments
 (0)