From b31794cda5a1c3b3dd75f7a63b0d52862c708e65 Mon Sep 17 00:00:00 2001 From: David Baker Date: Thu, 18 Jun 2015 15:03:57 +0100 Subject: [PATCH] Focus the text box at appropriate times --- src/molecules/MessageComposer.js | 18 ++++++++++++++++++ src/pages/MatrixChat.js | 10 ++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/molecules/MessageComposer.js b/src/molecules/MessageComposer.js index 61946252..56fcdb18 100644 --- a/src/molecules/MessageComposer.js +++ b/src/molecules/MessageComposer.js @@ -2,7 +2,25 @@ var React = require('react'); var MatrixClientPeg = require("../MatrixClientPeg"); +var dis = require("../dispatcher"); + module.exports = React.createClass({ + componentDidMount: function() { + this.dispatcherRef = dis.register(this.onAction); + }, + + componentWillUnmount: function() { + dis.unregister(this.dispatcherRef); + }, + + onAction: function(payload) { + switch (payload.action) { + case 'focus_composer': + this.refs.textarea.getDOMNode().focus(); + break; + } + }, + onKeyDown: function (ev) { if (ev.keyCode == 13) { var contentText = this.refs.textarea.getDOMNode().value; diff --git a/src/pages/MatrixChat.js b/src/pages/MatrixChat.js index 3990ec0b..4c5988b4 100644 --- a/src/pages/MatrixChat.js +++ b/src/pages/MatrixChat.js @@ -27,12 +27,20 @@ module.exports = React.createClass({ if (this.state.logged_in) { this.startMatrixClient(); } + this.focusComposer = false; }, componentWillUnmount: function() { dis.unregister(this.dispatcherRef); }, + componentDidUpdate: function() { + if (this.focusComposer) { + dis.dispatch({action: 'focus_composer'}); + this.focusComposer = false; + } + }, + onAction: function(payload) { switch (payload.action) { case 'logout': @@ -47,6 +55,7 @@ module.exports = React.createClass({ this.setState({ currentRoom: payload.room_id }); + this.focusComposer = true; break; } }, @@ -65,6 +74,7 @@ module.exports = React.createClass({ firstRoom = cli.getRooms()[0].roomId; } that.setState({ready: true, currentRoom: firstRoom}); + dis.dispatch({action: 'focus_composer'}); }); cli.startClient(); },