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

