Skip to content
Snippets Groups Projects
Unverified Commit f168256f authored by Paul Kaplan's avatar Paul Kaplan Committed by GitHub
Browse files

Merge pull request #1523 from paulkaplan/fix-gui-updating

Fix the GUI not updating when new project data is available
parents 73775d18 c670d4f1
No related branches found
No related tags found
No related merge requests found
...@@ -10,6 +10,7 @@ import { ...@@ -10,6 +10,7 @@ import {
} from '../reducers/modals'; } from '../reducers/modals';
import {activateTab, COSTUMES_TAB_INDEX} from '../reducers/editor-tab'; import {activateTab, COSTUMES_TAB_INDEX} from '../reducers/editor-tab';
import {setReceivedBlocks} from '../reducers/hovered-target';
import TargetPaneComponent from '../components/target-pane/target-pane.jsx'; import TargetPaneComponent from '../components/target-pane/target-pane.jsx';
import spriteLibraryContent from '../lib/libraries/sprites.json'; import spriteLibraryContent from '../lib/libraries/sprites.json';
...@@ -18,6 +19,7 @@ class TargetPane extends React.Component { ...@@ -18,6 +19,7 @@ class TargetPane extends React.Component {
constructor (props) { constructor (props) {
super(props); super(props);
bindAll(this, [ bindAll(this, [
'handleBlockDragEnd',
'handleChangeSpriteDirection', 'handleChangeSpriteDirection',
'handleChangeSpriteName', 'handleChangeSpriteName',
'handleChangeSpriteSize', 'handleChangeSpriteSize',
...@@ -31,6 +33,12 @@ class TargetPane extends React.Component { ...@@ -31,6 +33,12 @@ class TargetPane extends React.Component {
'handlePaintSpriteClick' 'handlePaintSpriteClick'
]); ]);
} }
componentDidMount () {
this.props.vm.addListener('BLOCK_DRAG_END', this.handleBlockDragEnd);
}
componentWillUnmount () {
this.props.vm.removeListener('BLOCK_DRAG_END', this.handleBlockDragEnd);
}
handleChangeSpriteDirection (direction) { handleChangeSpriteDirection (direction) {
this.props.vm.postSpriteInfo({direction}); this.props.vm.postSpriteInfo({direction});
} }
...@@ -71,6 +79,12 @@ class TargetPane extends React.Component { ...@@ -71,6 +79,12 @@ class TargetPane extends React.Component {
}); });
} }
} }
handleBlockDragEnd (blocks) {
if (this.props.hoveredTarget.sprite && this.props.hoveredTarget.sprite !== this.props.editingTarget) {
this.props.vm.shareBlocksToTarget(blocks, this.props.hoveredTarget.sprite);
this.props.onReceivedBlocks(true);
}
}
render () { render () {
const { const {
onActivateTab, // eslint-disable-line no-unused-vars onActivateTab, // eslint-disable-line no-unused-vars
...@@ -134,6 +148,9 @@ const mapDispatchToProps = dispatch => ({ ...@@ -134,6 +148,9 @@ const mapDispatchToProps = dispatch => ({
}, },
onActivateTab: tabIndex => { onActivateTab: tabIndex => {
dispatch(activateTab(tabIndex)); dispatch(activateTab(tabIndex));
},
onReceivedBlocks: receivedBlocks => {
dispatch(setReceivedBlocks(receivedBlocks));
} }
}); });
......
...@@ -8,7 +8,6 @@ import {connect} from 'react-redux'; ...@@ -8,7 +8,6 @@ import {connect} from 'react-redux';
import {updateEditingTarget, updateTargets} from '../reducers/targets'; import {updateEditingTarget, updateTargets} from '../reducers/targets';
import {updateBlockDrag} from '../reducers/block-drag'; import {updateBlockDrag} from '../reducers/block-drag';
import {updateMonitors} from '../reducers/monitors'; import {updateMonitors} from '../reducers/monitors';
import {setReceivedBlocks} from '../reducers/hovered-target';
/* /*
* Higher Order Component to manage events emitted by the VM * Higher Order Component to manage events emitted by the VM
...@@ -20,7 +19,6 @@ const vmListenerHOC = function (WrappedComponent) { ...@@ -20,7 +19,6 @@ const vmListenerHOC = function (WrappedComponent) {
constructor (props) { constructor (props) {
super(props); super(props);
bindAll(this, [ bindAll(this, [
'handleBlockDragEnd',
'handleKeyDown', 'handleKeyDown',
'handleKeyUp' 'handleKeyUp'
]); ]);
...@@ -33,8 +31,6 @@ const vmListenerHOC = function (WrappedComponent) { ...@@ -33,8 +31,6 @@ const vmListenerHOC = function (WrappedComponent) {
this.props.vm.on('targetsUpdate', this.props.onTargetsUpdate); this.props.vm.on('targetsUpdate', this.props.onTargetsUpdate);
this.props.vm.on('MONITORS_UPDATE', this.props.onMonitorsUpdate); this.props.vm.on('MONITORS_UPDATE', this.props.onMonitorsUpdate);
this.props.vm.on('BLOCK_DRAG_UPDATE', this.props.onBlockDragUpdate); this.props.vm.on('BLOCK_DRAG_UPDATE', this.props.onBlockDragUpdate);
this.props.vm.on('BLOCK_DRAG_END', this.handleBlockDragEnd);
} }
componentDidMount () { componentDidMount () {
if (this.props.attachKeyboardEvents) { if (this.props.attachKeyboardEvents) {
...@@ -42,21 +38,12 @@ const vmListenerHOC = function (WrappedComponent) { ...@@ -42,21 +38,12 @@ const vmListenerHOC = function (WrappedComponent) {
document.addEventListener('keyup', this.handleKeyUp); document.addEventListener('keyup', this.handleKeyUp);
} }
} }
shouldComponentUpdate () {
return false;
}
componentWillUnmount () { componentWillUnmount () {
if (this.props.attachKeyboardEvents) { if (this.props.attachKeyboardEvents) {
document.removeEventListener('keydown', this.handleKeyDown); document.removeEventListener('keydown', this.handleKeyDown);
document.removeEventListener('keyup', this.handleKeyUp); document.removeEventListener('keyup', this.handleKeyUp);
} }
} }
handleBlockDragEnd (blocks) {
if (this.props.hoveredSprite && this.props.hoveredSprite !== this.props.editingTarget) {
this.props.vm.shareBlocksToTarget(blocks, this.props.hoveredSprite);
this.props.onReceivedBlocks(true);
}
}
handleKeyDown (e) { handleKeyDown (e) {
// Don't capture keys intended for Blockly inputs. // Don't capture keys intended for Blockly inputs.
if (e.target !== document && e.target !== document.body) return; if (e.target !== document && e.target !== document.body) return;
...@@ -88,13 +75,10 @@ const vmListenerHOC = function (WrappedComponent) { ...@@ -88,13 +75,10 @@ const vmListenerHOC = function (WrappedComponent) {
const { const {
/* eslint-disable no-unused-vars */ /* eslint-disable no-unused-vars */
attachKeyboardEvents, attachKeyboardEvents,
editingTarget,
hoveredSprite,
onBlockDragUpdate, onBlockDragUpdate,
onKeyDown, onKeyDown,
onKeyUp, onKeyUp,
onMonitorsUpdate, onMonitorsUpdate,
onReceivedBlocks,
onTargetsUpdate, onTargetsUpdate,
/* eslint-enable no-unused-vars */ /* eslint-enable no-unused-vars */
...props ...props
...@@ -104,13 +88,10 @@ const vmListenerHOC = function (WrappedComponent) { ...@@ -104,13 +88,10 @@ const vmListenerHOC = function (WrappedComponent) {
} }
VMListener.propTypes = { VMListener.propTypes = {
attachKeyboardEvents: PropTypes.bool, attachKeyboardEvents: PropTypes.bool,
editingTarget: PropTypes.string,
hoveredSprite: PropTypes.string,
onBlockDragUpdate: PropTypes.func.isRequired, onBlockDragUpdate: PropTypes.func.isRequired,
onKeyDown: PropTypes.func, onKeyDown: PropTypes.func,
onKeyUp: PropTypes.func, onKeyUp: PropTypes.func,
onMonitorsUpdate: PropTypes.func.isRequired, onMonitorsUpdate: PropTypes.func.isRequired,
onReceivedBlocks: PropTypes.func.isRequired,
onTargetsUpdate: PropTypes.func.isRequired, onTargetsUpdate: PropTypes.func.isRequired,
vm: PropTypes.instanceOf(VM).isRequired vm: PropTypes.instanceOf(VM).isRequired
}; };
...@@ -132,9 +113,6 @@ const vmListenerHOC = function (WrappedComponent) { ...@@ -132,9 +113,6 @@ const vmListenerHOC = function (WrappedComponent) {
}, },
onBlockDragUpdate: areBlocksOverGui => { onBlockDragUpdate: areBlocksOverGui => {
dispatch(updateBlockDrag(areBlocksOverGui)); dispatch(updateBlockDrag(areBlocksOverGui));
},
onReceivedBlocks: receivedBlocks => {
dispatch(setReceivedBlocks(receivedBlocks));
} }
}); });
return connect( return connect(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment