diff --git a/css/molecules/RoomTile.css b/css/molecules/RoomTile.css new file mode 100644 index 00000000..e50ab7b0 --- /dev/null +++ b/css/molecules/RoomTile.css @@ -0,0 +1,18 @@ +.mx_RoomTile { + height: 20px; + width: 250px; + background-color: #ddd; + margin-top: 1px; + margin-bottom: 1px; + padding: 5px; +} + +.mx_RoomTile_name { + font-size: 80%; + font-weight: bold; +} + +.mx_RoomTile div { + overflow: hidden; + text-overflow: ellipsis; +} diff --git a/css/organisms/RoomList.css b/css/organisms/RoomList.css new file mode 100644 index 00000000..40d37526 --- /dev/null +++ b/css/organisms/RoomList.css @@ -0,0 +1,3 @@ +.mx_RoomList ul { + padding: 0px; +} diff --git a/src/MatrixClientPeg.js b/src/MatrixClientPeg.js index eed8093a..ee417174 100644 --- a/src/MatrixClientPeg.js +++ b/src/MatrixClientPeg.js @@ -14,7 +14,6 @@ if (localStorage) { accessToken: access_token, userId: user_id }); - matrixClient.startClient(); } } diff --git a/src/organisms/ThreadSection.js b/src/molecules/RoomTile.js similarity index 55% rename from src/organisms/ThreadSection.js rename to src/molecules/RoomTile.js index 0a80ef8c..09a781ab 100644 --- a/src/organisms/ThreadSection.js +++ b/src/molecules/RoomTile.js @@ -3,11 +3,9 @@ var React = require('react'); module.exports = React.createClass({ render: function() { return ( -
- +
+
{this.props.room.name}
); } }); - diff --git a/src/organisms/RoomList.js b/src/organisms/RoomList.js new file mode 100644 index 00000000..a2d18ac2 --- /dev/null +++ b/src/organisms/RoomList.js @@ -0,0 +1,32 @@ +var React = require('react'); + +var MatrixClientPeg = require("../MatrixClientPeg"); + +var RoomTile = require("../molecules/RoomTile"); + +module.exports = React.createClass({ + componentWillMount: function() { + var cli = MatrixClientPeg.get(); + + this.setState({roomList: cli.getRooms()}); + }, + + makeRoomTiles: function() { + return this.state.roomList.map(function(room) { + return ( + + ); + }); + }, + + render: function() { + return ( +
+
    + {this.makeRoomTiles()} +
+
+ ); + } +}); + diff --git a/src/pages/MatrixChat.js b/src/pages/MatrixChat.js index 2b639d19..f72526a1 100644 --- a/src/pages/MatrixChat.js +++ b/src/pages/MatrixChat.js @@ -1,7 +1,8 @@ var React = require('react'); -var ThreadSection = require('../organisms/ThreadSection'); +var RoomList = require('../organisms/RoomList'); var MessageSection = require('../organisms/MessageSection'); +var Loader = require("react-loader"); var Login = require('../templates/Login'); @@ -12,22 +13,43 @@ var mxCliPeg = require("../MatrixClientPeg"); module.exports = React.createClass({ getInitialState: function() { return { - logged_in: !!(mxCliPeg.get() && mxCliPeg.get().credentials) + logged_in: !!(mxCliPeg.get() && mxCliPeg.get().credentials), + ready: false }; }, + componentDidMount: function() { + if (this.state.logged_in) { + this.startMatrixClient(); + } + }, + onLoggedIn: function() { this.setState({logged_in: true}); + this.startMatrixClient(); + }, + + startMatrixClient: function() { + var cli = mxCliPeg.get(); + var that = this; + cli.on('syncComplete', function() { + that.setState({ready: true}); + }); + cli.startClient(); }, render: function() { - if (this.state.logged_in) { + if (this.state.logged_in && this.state.ready) { return (
- +
); + } else if (this.state.logged_in) { + return ( + + ); } else { return (