From c4764af9a28f860eabcb23e359254d6250174859 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Tue, 14 Jul 2015 17:27:22 +0100 Subject: [PATCH] Add phases to CreateRoom organism --- skins/base/views/organisms/CreateRoom.js | 32 ++++++++++++++++++------ src/controllers/organisms/CreateRoom.js | 32 ++++++++++++++++++++++-- 2 files changed, 54 insertions(+), 10 deletions(-) diff --git a/skins/base/views/organisms/CreateRoom.js b/skins/base/views/organisms/CreateRoom.js index e6115f25..36f6e466 100644 --- a/skins/base/views/organisms/CreateRoom.js +++ b/skins/base/views/organisms/CreateRoom.js @@ -45,13 +45,29 @@ module.exports = React.createClass({ }, render: function() { - return ( -
- - - - -
- ); + var curr_phase = this.state.phase; + if (curr_phase == this.phases.CREATING) { + return ( +
Creating...
+ ); + } else { + var error_box = ""; + if (curr_phase == this.phases.ERROR) { + error_box = ( +
+ An error occured: {this.state.error_string} +
+ ); + } + return ( +
+ + + + + {error_box} +
+ ); + } } }); diff --git a/src/controllers/organisms/CreateRoom.js b/src/controllers/organisms/CreateRoom.js index 499585b0..f66893d9 100644 --- a/src/controllers/organisms/CreateRoom.js +++ b/src/controllers/organisms/CreateRoom.js @@ -24,12 +24,26 @@ module.exports = { onRoomCreated: React.PropTypes.func, }, + phases: { + CONFIG: "CONFIG", + CREATING: "CREATING", + CREATED: "CREATED", + ERROR: "ERROR", + }, + getDefaultProps: function() { return { onRoomCreated: function() {}, }; }, + getInitialState: function() { + return { + phase: this.phases.CONFIG, + error_string: "", + }; + }, + onCreateRoom: function() { var options = {}; @@ -57,8 +71,22 @@ module.exports = { var deferred = MatrixClientPeg.get().createRoom(options); - deferred.done(function () { - this.props.onRoomCreated(); + this.setState({ + phase: this.phases.CREATING, + }); + + var self = this; + + deferred.then(function () { + self.setState({ + phase: self.phases.CREATED, + }); + self.props.onRoomCreated(); + }, function(err) { + self.setState({ + phase: self.phases.ERROR, + error_string: err.toString(), + }); }); } };