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:
parent
0d49fcdbaa
commit
bcb6e3edca
1 changed files with 24 additions and 0 deletions
|
@ -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++;
|
||||
|
|
Loading…
Add table
Reference in a new issue