mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-14 02:06:29 +00:00
add hotkeys for planet switching
This commit is contained in:
@@ -21,9 +21,11 @@ module.exports = React.createClass({
|
|||||||
},
|
},
|
||||||
componentDidMount: function () {
|
componentDidMount: function () {
|
||||||
this.unsubscribe = AuthStore.listen(this.onLogout)
|
this.unsubscribe = AuthStore.listen(this.onLogout)
|
||||||
|
document.addEventListener('keydown', this.handleKeyDown)
|
||||||
},
|
},
|
||||||
componentWillUnmount: function () {
|
componentWillUnmount: function () {
|
||||||
this.unsubscribe()
|
this.unsubscribe()
|
||||||
|
document.removeEventListener('keydown', this.handleKeyDown)
|
||||||
},
|
},
|
||||||
onLogout: function () {
|
onLogout: function () {
|
||||||
this.transitionTo('login')
|
this.transitionTo('login')
|
||||||
@@ -40,11 +42,20 @@ module.exports = React.createClass({
|
|||||||
closePlanetCreateModal: function () {
|
closePlanetCreateModal: function () {
|
||||||
this.setState({isPlanetCreateModalOpen: false})
|
this.setState({isPlanetCreateModalOpen: false})
|
||||||
},
|
},
|
||||||
|
handleKeyDown: function (e) {
|
||||||
|
if (e.metaKey && e.keyCode > 48 && e.keyCode < 58) {
|
||||||
|
var planet = this.props.currentUser.Planets[e.keyCode - 49]
|
||||||
|
if (planet != null) {
|
||||||
|
this.transitionTo('planet', {userName: planet.userName, planetName: planet.name})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
e.preventDefault()
|
||||||
|
},
|
||||||
render: function () {
|
render: function () {
|
||||||
var planets = this.props.currentUser.Planets.map(function (planet, index) {
|
var planets = this.props.currentUser.Planets.map(function (planet, index) {
|
||||||
return (
|
return (
|
||||||
<li key={planet.id} className={this.props.currentPlanet != null && this.props.currentPlanet.name === planet.name ? 'active' : ''}>
|
<li key={planet.id} className={this.props.currentPlanet != null && this.props.currentPlanet.name === planet.name ? 'active' : ''}>
|
||||||
<Link to='planet' params={{userName: planet.userName, planetName: planet.name}} href>
|
<Link to='planet' params={{userName: planet.userName, planetName: planet.name}}>
|
||||||
{planet.name[0]}
|
{planet.name[0]}
|
||||||
<div className='planetTooltip'>{planet.userName}/{planet.name}</div>
|
<div className='planetTooltip'>{planet.userName}/{planet.name}</div>
|
||||||
</Link>
|
</Link>
|
||||||
|
|||||||
Reference in New Issue
Block a user