Preliminary keyboard shortcuts
This commit is contained in:
@ -89,10 +89,14 @@ class ContextMenu extends React.Component{
|
|||||||
selectedTracksUris.push( selectedTracks[i].uri );
|
selectedTracksUris.push( selectedTracks[i].uri );
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: figure out what index the currentTlTrack is (.indexOf()?)
|
var current_tltrack = this.props.mopidy.current_tltrack;
|
||||||
var currentTrackIndex = 1;
|
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();
|
this.props.uiActions.hideContextMenu();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -16,6 +16,29 @@ class TrackList extends React.Component{
|
|||||||
tracks: this.props.tracks,
|
tracks: this.props.tracks,
|
||||||
lastSelectedTrack: false
|
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 ){
|
componentWillReceiveProps( nextProps ){
|
||||||
@ -131,7 +154,7 @@ class TrackList extends React.Component{
|
|||||||
|
|
||||||
// see if we're the current tlTrack
|
// see if we're the current tlTrack
|
||||||
// TODO: figure out why this isn't fired when the tracklist changes
|
// 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;
|
track.playing = true;
|
||||||
}else{
|
}else{
|
||||||
track.playing = false;
|
track.playing = false;
|
||||||
|
|||||||
@ -61,7 +61,7 @@ export default function reducer(mopidy = {}, action){
|
|||||||
}
|
}
|
||||||
|
|
||||||
return Object.assign({}, mopidy, {
|
return Object.assign({}, mopidy, {
|
||||||
currentTlTrack: action.data,
|
current_tltrack: action.data,
|
||||||
tracks: tracks
|
tracks: tracks
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -20,10 +20,29 @@ class App extends React.Component{
|
|||||||
|
|
||||||
constructor(props){
|
constructor(props){
|
||||||
super(props);
|
super(props);
|
||||||
|
|
||||||
|
this.handleKeyUp = this.handleKeyUp.bind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount(){
|
componentWillMount(){
|
||||||
this.props.mopidyActions.connect();
|
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(){
|
render(){
|
||||||
|
|||||||
Reference in New Issue
Block a user