Merge pull request #2699 from paulkaplan/set-username

Add username setting to vm listener HOC
This commit is contained in:
Paul Kaplan authored and GitHub committed 2018-07-25 09:58:59 -04:00
commit 156e62c742
1 file changed
+11 -1
+11 -1
View File
@@ -37,6 +37,12 @@ const vmListenerHOC = function (WrappedComponent) {
document.addEventListener('keydown', this.handleKeyDown);
document.addEventListener('keyup', this.handleKeyUp);
}
this.props.vm.postIOData('userData', {username: this.props.username});
}
componentWillReceiveProps (newProps) {
if (newProps.username !== this.props.username) {
this.props.vm.postIOData('userData', {username: newProps.username});
}
}
componentWillUnmount () {
if (this.props.attachKeyboardEvents) {
@@ -72,6 +78,7 @@ const vmListenerHOC = function (WrappedComponent) {
const {
/* eslint-disable no-unused-vars */
attachKeyboardEvents,
username,
onBlockDragUpdate,
onKeyDown,
onKeyUp,
@@ -90,13 +97,16 @@ const vmListenerHOC = function (WrappedComponent) {
onKeyUp: PropTypes.func,
onMonitorsUpdate: PropTypes.func.isRequired,
onTargetsUpdate: PropTypes.func.isRequired,
username: PropTypes.string,
vm: PropTypes.instanceOf(VM).isRequired
};
VMListener.defaultProps = {
attachKeyboardEvents: true
};
const mapStateToProps = state => ({
vm: state.scratchGui.vm
vm: state.scratchGui.vm,
username: state.session && state.session.session ?
state.session.session.username : ''
});
const mapDispatchToProps = dispatch => ({
onTargetsUpdate: data => {