Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added the ability to use keyboard shortcuts for navigating between pages #669

Merged
merged 1 commit into from
Mar 12, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Added the ability to use keyboard shortcuts for navigating between pages
  • Loading branch information
JohnRawlins committed Mar 11, 2020
commit 3169b992033b1f8c2a43bf8d5cd4f7ea460fb69a
22 changes: 21 additions & 1 deletion packages/app/app/containers/ShortcutsContainer/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';
import {withRouter} from 'react-router-dom';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import * as Mousetrap from 'mousetrap';
Expand Down Expand Up @@ -98,13 +99,30 @@ class Shortcuts extends React.Component {
return false;
}

goToPreviousPage = () => {
const {history} = this.props;
if (history.index > 1 ) {
history.goBack();
}
}

goToNextPage = () => {
const {history} = this.props;
if (history.index < history.length - 1) {
history.goForward();
}
}


componentDidMount() {
Mousetrap.bind('space', this.handleSpaceBar);
Mousetrap.bind('enter', this.playCurrentSong);
Mousetrap.bind('up', this.increaseVolume);
Mousetrap.bind('down', this.decreaseVolume);
Mousetrap.bind('left', this.decreaseSeek);
Mousetrap.bind('right', this.increaseSeek);
Mousetrap.bind('alt+left', this.goToPreviousPage);
Mousetrap.bind('alt+right', this.goToNextPage);
Mousetrap.bind(['ctrl+right', 'command+right'], this.props.actions.nextSong);
Mousetrap.bind(['ctrl+left', 'command+left'], this.props.actions.previousSong);
Mousetrap.bind(['ctrl+top', 'command+top'], this.props.actions.unmute);
Expand All @@ -119,6 +137,8 @@ class Shortcuts extends React.Component {
'right',
'up',
'down',
'alt+left',
'alt+right',
'ctrl+right',
'command+right',
'ctrl+left',
Expand Down Expand Up @@ -153,4 +173,4 @@ function mapDispatchToProps(dispatch) {
};
}

export default connect(mapStateToProps, mapDispatchToProps)(Shortcuts);
export default withRouter(connect(mapStateToProps, mapDispatchToProps)(Shortcuts));