1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/web/ synced 2025-03-09 00:00:01 +01:00

add support for keyboard control to visualizations (closes #124)

This commit is contained in:
Steffen Vogel 2017-09-21 03:16:05 +02:00
parent 0d49fcdbaa
commit bcb6e3edca

View file

@ -82,12 +82,18 @@ class Visualization extends React.Component {
// TODO: Don't fetch token from local, use user-store!
const token = localStorage.getItem('token');
document.addEventListener('keydown', this.handleKeydown.bind(this));
AppDispatcher.dispatch({
type: 'visualizations/start-load',
token
});
}
componentWillUnmount() {
document.removeEventListener('keydown', this.handleKeydown.bind(this));
}
componentDidUpdate() {
if (this.state.visualization._id !== this.props.match.params.visualization) {
this.reloadVisualization();
@ -120,6 +126,24 @@ class Visualization extends React.Component {
}
}
handleKeydown(e) {
console.log(e);
switch (e.key) {
case ' ':
case 'p':
this.setState({ paused: !this.state.paused });
break;
case 'e':
this.setState({ editing: !this.state.editing });
break;
case 'f':
this.props.toggleFullscreen();
break;
default:
}
}
getNewWidgetKey() {
// Increase the counter and update the state
return this.state.last_widget_key++;