From 80f9ebadeff1f96fe2235e35cc5a1f80afd6dd58 Mon Sep 17 00:00:00 2001
From: Reed Garmsen <rgarmsen2295@gmail.com>
Date: Tue, 7 Jul 2015 11:22:58 -0700
Subject: Added errorchange listener to textbox that detects if inet is not
 connected.  Still do not have reliable way of checking if inet has
 reconnected

---
 web/react/components/textbox.jsx | 35 +++++++++++++++++++++++++++++++++--
 1 file changed, 33 insertions(+), 2 deletions(-)

(limited to 'web/react/components/textbox.jsx')

diff --git a/web/react/components/textbox.jsx b/web/react/components/textbox.jsx
index 6b746aa78..227d61e3f 100644
--- a/web/react/components/textbox.jsx
+++ b/web/react/components/textbox.jsx
@@ -8,11 +8,22 @@ var SocketStore = require('../stores/socket_store.jsx');
 var MsgTyping = require('./msg_typing.jsx');
 var MentionList = require('./mention_list.jsx');
 var CommandList = require('./command_list.jsx');
+var ErrorStore = require('../stores/error_store.jsx');
 
 var utils = require('../utils/utils.jsx');
 var Constants = require('../utils/constants.jsx');
 var ActionTypes = Constants.ActionTypes;
 
+function getStateFromStores() {
+    var error = ErrorStore.getLastError();
+
+    if (error) {
+        return { message: error.message };
+    } else {
+        return { message: null };
+    }
+}
+
 module.exports = React.createClass({
     caret: -1,
     addedMention: false,
@@ -20,6 +31,8 @@ module.exports = React.createClass({
     mentions: [],
     componentDidMount: function() {
         PostStore.addAddMentionListener(this._onChange);
+        ErrorStore.addChangeListener(this._onError);
+        //SocketStore.addChangeListener(this._onSocketChange);
 
         this.resize();
         this.processMentions();
@@ -27,11 +40,29 @@ module.exports = React.createClass({
     },
     componentWillUnmount: function() {
         PostStore.removeAddMentionListener(this._onChange);
+        ErrorStore.removeChangeListener(this._onError);
     },
     _onChange: function(id, username) {
         if (id !== this.props.id) return;
         this.addMention(username);
     },
+    _onError: function() {
+        var errorState = getStateFromStores();
+
+        if (errorState.message === "There appears to be a problem with your internet connection") {
+            this.setState({ connection: " bad-connection" });
+        }
+        else {
+            console.log("Logged the error correctly");
+            this.setState({ connection: "" });
+        }
+    },
+    /*_onSocketChange: function() {
+        if (SocketStore.isSocketClosed())
+            this.setState({ connection: " bad-connection" });
+        else
+            this.setState({ connection: "" });
+    },*/
     componentDidUpdate: function() {
         if (this.caret >= 0) {
             utils.setCaretPosition(this.refs.message.getDOMNode(), this.caret)
@@ -57,7 +88,7 @@ module.exports = React.createClass({
         this.resize();
     },
     getInitialState: function() {
-        return { mentionText: '-1', mentions: [] };
+        return { mentionText: '-1', mentions: [], connection: "" };
     },
     updateMentionTab: function(mentionText, excludeList) {
         var self = this;
@@ -287,7 +318,7 @@ module.exports = React.createClass({
             <div ref="wrapper" className="textarea-wrapper">
                 <CommandList ref='commands' addCommand={this.addCommand} channelId={this.props.channelId} />
                 <div className="form-control textarea-div" ref="textdiv"/>
-                <textarea id={this.props.id} ref="message" className="form-control custom-textarea" spellCheck="true" autoComplete="off" autoCorrect="off" rows="1" placeholder={this.props.createMessage} value={this.props.messageText} onInput={this.handleChange} onChange={this.handleChange} onKeyPress={this.handleKeyPress} onKeyDown={this.handleKeyDown} onScroll={this.scroll} onFocus={this.handleFocus} onBlur={this.handleBlur} onPaste={this.handlePaste} />
+                <textarea id={this.props.id} ref="message" className={"form-control custom-textarea" + this.state.connection} spellCheck="true" autoComplete="off" autoCorrect="off" rows="1" placeholder={this.props.createMessage} value={this.props.messageText} onInput={this.handleChange} onChange={this.handleChange} onKeyPress={this.handleKeyPress} onKeyDown={this.handleKeyDown} onScroll={this.scroll} onFocus={this.handleFocus} onBlur={this.handleBlur} onPaste={this.handlePaste} />
             </div>
         );
     }
-- 
cgit v1.2.3-1-g7c22


From 56f369cfd1c8a480a1e70a10564670153dae2ff2 Mon Sep 17 00:00:00 2001
From: Reed Garmsen <rgarmsen2295@gmail.com>
Date: Thu, 9 Jul 2015 17:49:02 -0700
Subject: Use the AsyncClient call 'updateLastViewedAt' as a way of checking
 for inet connectivity immediately after clearning yellow bar after user has
 typed 5 characters

---
 web/react/components/textbox.jsx | 24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)

(limited to 'web/react/components/textbox.jsx')

diff --git a/web/react/components/textbox.jsx b/web/react/components/textbox.jsx
index 227d61e3f..db28fe3ab 100644
--- a/web/react/components/textbox.jsx
+++ b/web/react/components/textbox.jsx
@@ -9,6 +9,7 @@ var MsgTyping = require('./msg_typing.jsx');
 var MentionList = require('./mention_list.jsx');
 var CommandList = require('./command_list.jsx');
 var ErrorStore = require('../stores/error_store.jsx');
+var AsyncClient = require('../utils/async_client.jsx');
 
 var utils = require('../utils/utils.jsx');
 var Constants = require('../utils/constants.jsx');
@@ -32,7 +33,6 @@ module.exports = React.createClass({
     componentDidMount: function() {
         PostStore.addAddMentionListener(this._onChange);
         ErrorStore.addChangeListener(this._onError);
-        //SocketStore.addChangeListener(this._onSocketChange);
 
         this.resize();
         this.processMentions();
@@ -53,16 +53,9 @@ module.exports = React.createClass({
             this.setState({ connection: " bad-connection" });
         }
         else {
-            console.log("Logged the error correctly");
             this.setState({ connection: "" });
         }
     },
-    /*_onSocketChange: function() {
-        if (SocketStore.isSocketClosed())
-            this.setState({ connection: " bad-connection" });
-        else
-            this.setState({ connection: "" });
-    },*/
     componentDidUpdate: function() {
         if (this.caret >= 0) {
             utils.setCaretPosition(this.refs.message.getDOMNode(), this.caret)
@@ -88,7 +81,7 @@ module.exports = React.createClass({
         this.resize();
     },
     getInitialState: function() {
-        return { mentionText: '-1', mentions: [], connection: "" };
+        return { mentionText: '-1', mentions: [], connection: "", numPresses: 0 };
     },
     updateMentionTab: function(mentionText, excludeList) {
         var self = this;
@@ -120,6 +113,19 @@ module.exports = React.createClass({
     handleKeyPress: function(e) {
         var text = this.refs.message.getDOMNode().value;
 
+        if (this.state.connection === " bad-connection" && this.state.numPresses > 5) {
+            AppDispatcher.handleServerAction({
+                type: ActionTypes.RECIEVED_ERROR,
+                err: null
+            });
+            this.setState({ numPresses: 0 });
+
+            AsyncClient.updateLastViewedAt();
+        }
+        else if (this.state.connection === " bad-connection") {
+            this.setState({ numPresses: this.state.numPresses + 1 });
+        }
+
         if (!this.refs.commands.isEmpty() && text.indexOf("/") == 0 && e.which==13) {
             this.refs.commands.addFirstCommand();
             e.preventDefault();
-- 
cgit v1.2.3-1-g7c22


From 7f0d070bf107502a96c5271cc2bc939bd115362a Mon Sep 17 00:00:00 2001
From: Reed Garmsen <rgarmsen2295@gmail.com>
Date: Thu, 9 Jul 2015 17:59:13 -0700
Subject: Added performance comment

---
 web/react/components/textbox.jsx | 2 ++
 1 file changed, 2 insertions(+)

(limited to 'web/react/components/textbox.jsx')

diff --git a/web/react/components/textbox.jsx b/web/react/components/textbox.jsx
index db28fe3ab..16219156d 100644
--- a/web/react/components/textbox.jsx
+++ b/web/react/components/textbox.jsx
@@ -113,6 +113,8 @@ module.exports = React.createClass({
     handleKeyPress: function(e) {
         var text = this.refs.message.getDOMNode().value;
 
+        //Since these should only happen when you have no connection and slightly briefly after any
+        //performance hit should not matter
         if (this.state.connection === " bad-connection" && this.state.numPresses > 5) {
             AppDispatcher.handleServerAction({
                 type: ActionTypes.RECIEVED_ERROR,
-- 
cgit v1.2.3-1-g7c22


From eb99363169902574d41e8037ea0d2de4770dcb5a Mon Sep 17 00:00:00 2001
From: Reed Garmsen <rgarmsen2295@gmail.com>
Date: Thu, 9 Jul 2015 18:17:40 -0700
Subject: Changed method again this time to a timer based system so that when
 inet does come back the yellow tinge goes away automatically not on user
 input

---
 web/react/components/textbox.jsx | 43 +++++++++++++++++++++++++---------------
 1 file changed, 27 insertions(+), 16 deletions(-)

(limited to 'web/react/components/textbox.jsx')

diff --git a/web/react/components/textbox.jsx b/web/react/components/textbox.jsx
index 16219156d..161b30646 100644
--- a/web/react/components/textbox.jsx
+++ b/web/react/components/textbox.jsx
@@ -51,9 +51,35 @@ module.exports = React.createClass({
 
         if (errorState.message === "There appears to be a problem with your internet connection") {
             this.setState({ connection: " bad-connection" });
+            var timerInterrupt = window.setInterval(this._onTimerInterrupt, 5000);
+            this.setState({ timerInterrupt: timerInterrupt });
         }
         else {
             this.setState({ connection: "" });
+            if (this.state.timerInterrupt != null) {
+                window.clearInterval(this.state.timerInterrupt);
+                this.setState({ timerInterrupt: null });
+            }
+        }
+    },
+    _onTimerInterrupt: function() {
+        //Since these should only happen when you have no connection and slightly briefly after any
+        //performance hit should not matter
+        if (this.state.connection === " bad-connection") {
+            AppDispatcher.handleServerAction({
+                type: ActionTypes.RECIEVED_ERROR,
+                err: null
+            });
+            this.setState({ numPresses: 0 });
+
+
+            window.clearInterval(this.state.timerInterrupt);
+            this.setState({ timerInterrupt: null });
+            AsyncClient.updateLastViewedAt();
+        }
+        else {
+            window.clearInterval(this.state.timerInterrupt);
+            this.setState({ timerInterrupt: null });
         }
     },
     componentDidUpdate: function() {
@@ -81,7 +107,7 @@ module.exports = React.createClass({
         this.resize();
     },
     getInitialState: function() {
-        return { mentionText: '-1', mentions: [], connection: "", numPresses: 0 };
+        return { mentionText: '-1', mentions: [], connection: "", timerInterrupt: null };
     },
     updateMentionTab: function(mentionText, excludeList) {
         var self = this;
@@ -113,21 +139,6 @@ module.exports = React.createClass({
     handleKeyPress: function(e) {
         var text = this.refs.message.getDOMNode().value;
 
-        //Since these should only happen when you have no connection and slightly briefly after any
-        //performance hit should not matter
-        if (this.state.connection === " bad-connection" && this.state.numPresses > 5) {
-            AppDispatcher.handleServerAction({
-                type: ActionTypes.RECIEVED_ERROR,
-                err: null
-            });
-            this.setState({ numPresses: 0 });
-
-            AsyncClient.updateLastViewedAt();
-        }
-        else if (this.state.connection === " bad-connection") {
-            this.setState({ numPresses: this.state.numPresses + 1 });
-        }
-
         if (!this.refs.commands.isEmpty() && text.indexOf("/") == 0 && e.which==13) {
             this.refs.commands.addFirstCommand();
             e.preventDefault();
-- 
cgit v1.2.3-1-g7c22


From 582c94cee97748b20af732cab6442c2a90a15100 Mon Sep 17 00:00:00 2001
From: Reed Garmsen <rgarmsen2295@gmail.com>
Date: Thu, 9 Jul 2015 18:18:59 -0700
Subject: Removed newline

---
 web/react/components/textbox.jsx | 1 -
 1 file changed, 1 deletion(-)

(limited to 'web/react/components/textbox.jsx')

diff --git a/web/react/components/textbox.jsx b/web/react/components/textbox.jsx
index 161b30646..718ecbe4c 100644
--- a/web/react/components/textbox.jsx
+++ b/web/react/components/textbox.jsx
@@ -72,7 +72,6 @@ module.exports = React.createClass({
             });
             this.setState({ numPresses: 0 });
 
-
             window.clearInterval(this.state.timerInterrupt);
             this.setState({ timerInterrupt: null });
             AsyncClient.updateLastViewedAt();
-- 
cgit v1.2.3-1-g7c22


From b4b0e92fd49c50d5e5125a1092d71fc5832b468b Mon Sep 17 00:00:00 2001
From: Reed Garmsen <rgarmsen2295@gmail.com>
Date: Thu, 9 Jul 2015 18:23:14 -0700
Subject: Moved check for existing timer interrupt outside of if-else block for
 sanity

---
 web/react/components/textbox.jsx | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

(limited to 'web/react/components/textbox.jsx')

diff --git a/web/react/components/textbox.jsx b/web/react/components/textbox.jsx
index 718ecbe4c..b5b696124 100644
--- a/web/react/components/textbox.jsx
+++ b/web/react/components/textbox.jsx
@@ -49,6 +49,11 @@ module.exports = React.createClass({
     _onError: function() {
         var errorState = getStateFromStores();
 
+        if (this.state.timerInterrupt != null) {
+            window.clearInterval(this.state.timerInterrupt);
+            this.setState({ timerInterrupt: null });
+        }
+
         if (errorState.message === "There appears to be a problem with your internet connection") {
             this.setState({ connection: " bad-connection" });
             var timerInterrupt = window.setInterval(this._onTimerInterrupt, 5000);
@@ -56,10 +61,6 @@ module.exports = React.createClass({
         }
         else {
             this.setState({ connection: "" });
-            if (this.state.timerInterrupt != null) {
-                window.clearInterval(this.state.timerInterrupt);
-                this.setState({ timerInterrupt: null });
-            }
         }
     },
     _onTimerInterrupt: function() {
-- 
cgit v1.2.3-1-g7c22


From d2e046a98ca235506ee74b34887ac9f5b13c2ac3 Mon Sep 17 00:00:00 2001
From: Reed Garmsen <rgarmsen2295@gmail.com>
Date: Fri, 10 Jul 2015 08:39:37 -0700
Subject: Changed spacing model of connection flag & removed unnecessary
 duplication of logic

---
 web/react/components/textbox.jsx | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)

(limited to 'web/react/components/textbox.jsx')

diff --git a/web/react/components/textbox.jsx b/web/react/components/textbox.jsx
index b5b696124..7e5f8e2f4 100644
--- a/web/react/components/textbox.jsx
+++ b/web/react/components/textbox.jsx
@@ -55,7 +55,7 @@ module.exports = React.createClass({
         }
 
         if (errorState.message === "There appears to be a problem with your internet connection") {
-            this.setState({ connection: " bad-connection" });
+            this.setState({ connection: "bad-connection" });
             var timerInterrupt = window.setInterval(this._onTimerInterrupt, 5000);
             this.setState({ timerInterrupt: timerInterrupt });
         }
@@ -66,21 +66,18 @@ module.exports = React.createClass({
     _onTimerInterrupt: function() {
         //Since these should only happen when you have no connection and slightly briefly after any
         //performance hit should not matter
-        if (this.state.connection === " bad-connection") {
+        if (this.state.connection === "bad-connection") {
             AppDispatcher.handleServerAction({
                 type: ActionTypes.RECIEVED_ERROR,
                 err: null
             });
             this.setState({ numPresses: 0 });
 
-            window.clearInterval(this.state.timerInterrupt);
-            this.setState({ timerInterrupt: null });
             AsyncClient.updateLastViewedAt();
         }
-        else {
-            window.clearInterval(this.state.timerInterrupt);
-            this.setState({ timerInterrupt: null });
-        }
+        
+        window.clearInterval(this.state.timerInterrupt);
+        this.setState({ timerInterrupt: null });
     },
     componentDidUpdate: function() {
         if (this.caret >= 0) {
@@ -337,7 +334,7 @@ module.exports = React.createClass({
             <div ref="wrapper" className="textarea-wrapper">
                 <CommandList ref='commands' addCommand={this.addCommand} channelId={this.props.channelId} />
                 <div className="form-control textarea-div" ref="textdiv"/>
-                <textarea id={this.props.id} ref="message" className={"form-control custom-textarea" + this.state.connection} spellCheck="true" autoComplete="off" autoCorrect="off" rows="1" placeholder={this.props.createMessage} value={this.props.messageText} onInput={this.handleChange} onChange={this.handleChange} onKeyPress={this.handleKeyPress} onKeyDown={this.handleKeyDown} onScroll={this.scroll} onFocus={this.handleFocus} onBlur={this.handleBlur} onPaste={this.handlePaste} />
+                <textarea id={this.props.id} ref="message" className={"form-control custom-textarea " + this.state.connection} spellCheck="true" autoComplete="off" autoCorrect="off" rows="1" placeholder={this.props.createMessage} value={this.props.messageText} onInput={this.handleChange} onChange={this.handleChange} onKeyPress={this.handleKeyPress} onKeyDown={this.handleKeyDown} onScroll={this.scroll} onFocus={this.handleFocus} onBlur={this.handleBlur} onPaste={this.handlePaste} />
             </div>
         );
     }
-- 
cgit v1.2.3-1-g7c22


From 184eac99ddd329fcd803f938f193572cc64f842e Mon Sep 17 00:00:00 2001
From: Reed Garmsen <rgarmsen2295@gmail.com>
Date: Fri, 10 Jul 2015 08:40:38 -0700
Subject: Removed extraneous setState

---
 web/react/components/textbox.jsx | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

(limited to 'web/react/components/textbox.jsx')

diff --git a/web/react/components/textbox.jsx b/web/react/components/textbox.jsx
index 7e5f8e2f4..ad50b7920 100644
--- a/web/react/components/textbox.jsx
+++ b/web/react/components/textbox.jsx
@@ -71,11 +71,10 @@ module.exports = React.createClass({
                 type: ActionTypes.RECIEVED_ERROR,
                 err: null
             });
-            this.setState({ numPresses: 0 });
 
             AsyncClient.updateLastViewedAt();
         }
-        
+
         window.clearInterval(this.state.timerInterrupt);
         this.setState({ timerInterrupt: null });
     },
-- 
cgit v1.2.3-1-g7c22

