From 0dde507eddabadeee07a2ba8496c7a9ae69b9d27 Mon Sep 17 00:00:00 2001
From: Paul Kaplan <pkaplan@media.mit.edu>
Date: Mon, 23 Jul 2018 10:00:44 -0400
Subject: [PATCH] Add username setting to vm listener HOC

---
 src/lib/vm-listener-hoc.jsx | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/src/lib/vm-listener-hoc.jsx b/src/lib/vm-listener-hoc.jsx
index 3fd9e2096..28f578b37 100644
--- a/src/lib/vm-listener-hoc.jsx
+++ b/src/lib/vm-listener-hoc.jsx
@@ -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 => {
-- 
GitLab