Preliminary keyboard shortcuts

This commit is contained in:
James Barnsley
2016-10-27 13:02:10 +13:00
parent 560fb4df19
commit 1408d5c4cc
4 changed files with 52 additions and 6 deletions

View File

@ -89,10 +89,14 @@ class ContextMenu extends React.Component{
selectedTracksUris.push( selectedTracks[i].uri );
}
// TODO: figure out what index the currentTlTrack is (.indexOf()?)
var currentTrackIndex = 1;
var current_tltrack = this.props.mopidy.current_tltrack;
function isCurrentTlid( tltrack ){
return ( tltrack.tlid == current_tltrack.tlid );
}
var currentTrack = this.props.mopidy.tracks.find( isCurrentTlid );
var currentTrackIndex = this.props.mopidy.tracks.indexOf( currentTrack );
this.props.mopidyActions.enqueueTracks(selectedTracksUris, currentTrackIndex);
this.props.mopidyActions.enqueueTracks(selectedTracksUris, currentTrackIndex+1);
this.props.uiActions.hideContextMenu();
}

View File

@ -16,6 +16,29 @@ class TrackList extends React.Component{
tracks: this.props.tracks,
lastSelectedTrack: false
}
this.handleKeyUp = this.handleKeyUp.bind(this)
}
componentWillMount(){
window.addEventListener("keyup", this.handleKeyUp, false);
}
componentWillUnmount(){
window.removeEventListener("keyup", this.handleKeyUp, false);
}
handleKeyUp(e){
switch(e.keyCode){
case 13: // enter
this.playTrack( this.state.tracks[this.state.lastSelectedTrack] );
break;
case 46: // delete
console.log('delete')
break;
}
}
componentWillReceiveProps( nextProps ){
@ -131,7 +154,7 @@ class TrackList extends React.Component{
// see if we're the current tlTrack
// TODO: figure out why this isn't fired when the tracklist changes
if( self.props.mopidy.trackInFocus && self.props.mopidy.trackInFocus.tlid == track.tlid ){
if( self.props.mopidy.current_tltrack && self.props.mopidy.current_tltrack.tlid == track.tlid ){
track.playing = true;
}else{
track.playing = false;

View File

@ -61,7 +61,7 @@ export default function reducer(mopidy = {}, action){
}
return Object.assign({}, mopidy, {
currentTlTrack: action.data,
current_tltrack: action.data,
tracks: tracks
});

View File

@ -20,10 +20,29 @@ class App extends React.Component{
constructor(props){
super(props);
this.handleKeyUp = this.handleKeyUp.bind(this);
}
componentDidMount(){
componentWillMount(){
this.props.mopidyActions.connect();
window.addEventListener("keyup", this.handleKeyUp, false);
}
componentWillUnmount(){
window.removeEventListener("keyup", this.handleKeyUp, false);
}
handleKeyUp(e){
switch(e.keyCode){
case 32: // spacebar
if( this.props.mopidy.state == 'playing' ){
this.props.mopidyActions.pause();
}else{
this.props.mopidyActions.play();
}
break;
}
}
render(){