From 0e47716cc73cd072188944ece836ffb9776a4325 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Sat, 30 Dec 2017 10:43:45 -0500 Subject: [PATCH] Fix init hack --- src/index.js | 7 ------- src/ui/connection.js | 25 ++++++++++++++++--------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/index.js b/src/index.js index 710dd4b..14f9663 100644 --- a/src/index.js +++ b/src/index.js @@ -16,13 +16,7 @@ import Nav from './ui/navigation'; import Main from './ui/main'; import Connection from './ui/connection'; -let skip_init = false; - export function initialize(uri) { - if (skip_init) { - skip_init = false; - return; - } store.dispatch(socket_uri(uri)); store.dispatch(socket_update(SOCKET_STATE.CONNECTING)); ws_init(uri, () => { @@ -53,7 +47,6 @@ render(
); if (module.hot) { module.hot.accept('./ui/main.js', () => { const NextMain = require('./ui/main.js').default; - skip_init = true; render(); }); } diff --git a/src/ui/connection.js b/src/ui/connection.js index 7c7e6cb..5c4ab62 100644 --- a/src/ui/connection.js +++ b/src/ui/connection.js @@ -19,15 +19,22 @@ class ConnectionOverlay extends Component { constructor() { super(); this.connect = this.connect.bind(this); - const uri = localStorage.getItem("autoconnect"); - const password = localStorage.getItem("password"); - this.state = { - uri: uri || "ws://127.0.0.1:8412", - password, - autoconnect: !!uri - }; - if (uri) { - initialize(getURI(this.state.uri, this.state.password)); + this.componentDidMount = this.componentDidMount.bind(this); + } + + componentDidMount() { + const { socket } = this.props; + if (socket.state === SOCKET_STATE.DISCONNECTED) { + const uri = localStorage.getItem("autoconnect"); + const password = localStorage.getItem("password"); + this.state = { + uri: uri || "ws://127.0.0.1:8412", + password, + autoconnect: !!uri + }; + if (uri) { + initialize(getURI(this.state.uri, this.state.password)); + } } }