From ffb0dc78b8911344832c11a73b0a5466ca777543 Mon Sep 17 00:00:00 2001 From: David Baker Date: Fri, 12 Jun 2015 13:45:22 +0100 Subject: [PATCH] Fixes to login, and change to not use the dispatcher because it's just unnecessary here --- css/templates/Login.css | 1 + src/MatrixClientPeg.js | 1 + src/pages/MatrixChat.js | 13 ++++++++----- src/templates/Login.js | 16 ++++++++++++---- 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/css/templates/Login.css b/css/templates/Login.css index 10c28d7c35..4596edd120 100644 --- a/css/templates/Login.css +++ b/css/templates/Login.css @@ -7,5 +7,6 @@ text-align: center; background-color: #eee; border: 1px solid black; + position: relative; } diff --git a/src/MatrixClientPeg.js b/src/MatrixClientPeg.js index ee417174c9..eed8093adb 100644 --- a/src/MatrixClientPeg.js +++ b/src/MatrixClientPeg.js @@ -14,6 +14,7 @@ if (localStorage) { accessToken: access_token, userId: user_id }); + matrixClient.startClient(); } } diff --git a/src/pages/MatrixChat.js b/src/pages/MatrixChat.js index 01b9ebe247..0395450f46 100644 --- a/src/pages/MatrixChat.js +++ b/src/pages/MatrixChat.js @@ -7,24 +7,27 @@ var Login = require('../templates/Login'); var mxCliPeg = require("../MatrixClientPeg"); -var dis = require("../dispatcher"); +//var dis = require("../dispatcher"); module.exports = React.createClass({ getInitialState: function() { return { - logged_in: !!mxCliPeg.get().credentials + logged_in: !!(mxCliPeg.get() && mxCliPeg.get().credentials) }; }, - componentWillMount: function() { + /*componentWillMount: function() { var that = this; this.dispatcherRef = dis.register(function(payload) { switch(payload.action) { case 'logged_in': - that.setState({logged_in: true}); break; } }); + },*/ + + onLoggedIn: function() { + this.setState({logged_in: true}); }, render: function() { @@ -37,7 +40,7 @@ module.exports = React.createClass({ ); } else { return ( - + ); } } diff --git a/src/templates/Login.js b/src/templates/Login.js index 77518bb1f8..0700a3d0b6 100644 --- a/src/templates/Login.js +++ b/src/templates/Login.js @@ -6,7 +6,7 @@ var ServerConfig = require("../molecules/ServerConfig"); var ProgressBar = require("../molecules/ProgressBar"); var Loader = require("react-loader"); -var dis = require("../dispatcher"); +//var dis = require("../dispatcher"); module.exports = React.createClass({ getInitialState: function() { @@ -19,7 +19,7 @@ module.exports = React.createClass({ }, setStep: function(step) { - this.setState({ step: step, errorText: '' }); + this.setState({ step: step, errorText: '', busy: false }); }, onHSChosen: function(ev) { @@ -50,6 +50,11 @@ module.exports = React.createClass({ 'password': that.refs.pass.getDOMNode().value }).then(function(data) { // XXX: we assume this means we're logged in, but there could be a next stage + MatrixClientPeg.replace(Matrix.createClient({ + baseUrl: that.state.hs_url, + userId: data.user_id, + accessToken: data.access_token + })); var localStorage = window.localStorage; if (localStorage) { localStorage.setItem("mx_hs_url", that.state.hs_url); @@ -58,9 +63,12 @@ module.exports = React.createClass({ } else { console.warn("No local storage available: can't persist session!"); } - dis.dispatch({ + if (that.props.onLoggedIn) { + that.props.onLoggedIn(); + } + /*dis.dispatch({ 'action': 'logged_in' - }); + });*/ }, function(error) { that.setStep("stage_m.login.password"); that.setState({errorText: 'Login failed.'});