diff --git a/src/components/views/dialogs/DevtoolsDialog.js b/src/components/views/dialogs/DevtoolsDialog.js index a7ac9fb1..9c5948b4 100644 --- a/src/components/views/dialogs/DevtoolsDialog.js +++ b/src/components/views/dialogs/DevtoolsDialog.js @@ -23,17 +23,28 @@ class SendCustomEvent extends React.Component { static propTypes = { roomId: React.PropTypes.string.isRequired, onBack: React.PropTypes.func.isRequired, + + eventType: React.PropTypes.string.isRequired, + evContent: React.PropTypes.string.isRequired, + }; + + static defaultProps = { + eventType: '', + evContent: '{\n\n}', }; constructor(props, context) { super(props, context); this._send = this._send.bind(this); this.onBack = this.onBack.bind(this); - } + this._onChange = this._onChange.bind(this); - state = { - message: null, - }; + this.state = { + message: null, + input_eventType: this.props.eventType, + input_evContent: this.props.evContent, + }; + } onBack() { if (this.state.message) { @@ -51,13 +62,18 @@ class SendCustomEvent extends React.Component { } send(content) { - return MatrixClientPeg.get().sendEvent(this.props.roomId, this.refs.eventType.value, content); + return MatrixClientPeg.get().sendEvent(this.props.roomId, this.state.input_eventType, content); } async _send() { + if (this.state.input_eventType === '') { + this.setState({ message: _t('You must specify an event type!') }); + return; + } + let message; try { - const content = JSON.parse(this.refs.evContent.value); + const content = JSON.parse(this.state.input_evContent); await this.send(content); message = _t('Event sent!'); } catch (e) { @@ -67,7 +83,11 @@ class SendCustomEvent extends React.Component { } _additionalFields() { - return
; + return ; + } + + _onChange(e) { + this.setState({[`input_${e.target.id}`]: e.target.value}); } render() { @@ -87,14 +107,14 @@ class SendCustomEvent extends React.Component {{JSON.stringify(this.state.event, null, 2)}+
{JSON.stringify(this.state.event.event, null, 2)}