diff --git a/src/containers/visualization.js b/src/containers/visualization.js index 48911aa..fef662d 100644 --- a/src/containers/visualization.js +++ b/src/containers/visualization.js @@ -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++;