Browse Source

Fixes to login, and change to not use the dispatcher because it's just unnecessary here

pull/1/head
David Baker 7 years ago
parent
commit
ffb0dc78b8
  1. 1
      css/templates/Login.css
  2. 1
      src/MatrixClientPeg.js
  3. 13
      src/pages/MatrixChat.js
  4. 16
      src/templates/Login.js

1
css/templates/Login.css

@ -7,5 +7,6 @@
text-align: center;
background-color: #eee;
border: 1px solid black;
position: relative;
}

1
src/MatrixClientPeg.js

@ -14,6 +14,7 @@ if (localStorage) {
accessToken: access_token,
userId: user_id
});
matrixClient.startClient();
}
}

13
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 (
<Login />
<Login onLoggedIn={this.onLoggedIn} />
);
}
}

16
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.'});

Loading…
Cancel
Save