From 84f4fbe1428cbaea83eca7481459cf1cca179c4e Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Thu, 10 Aug 2017 23:55:22 +0100 Subject: [PATCH] DRY up code and change flow to be less destructive Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- .../views/dialogs/DevtoolsDialog.js | 130 ++++++++---------- 1 file changed, 61 insertions(+), 69 deletions(-) diff --git a/src/components/views/dialogs/DevtoolsDialog.js b/src/components/views/dialogs/DevtoolsDialog.js index b384cfdf0..f9ee7c5d2 100644 --- a/src/components/views/dialogs/DevtoolsDialog.js +++ b/src/components/views/dialogs/DevtoolsDialog.js @@ -16,7 +16,6 @@ limitations under the License. import React from 'react'; import sdk from 'matrix-react-sdk'; -import Modal from 'matrix-react-sdk/lib/Modal'; import MatrixClientPeg from 'matrix-react-sdk/lib/MatrixClientPeg'; class SendCustomEvent extends React.Component { @@ -28,33 +27,56 @@ class SendCustomEvent extends React.Component { constructor(props, context) { super(props, context); this._send = this._send.bind(this); + this.onBack = this.onBack.bind(this); } - async _send() { - try { - const content = JSON.parse(this.refs.evContent.value); - await MatrixClientPeg.get().sendEvent(this.refs.roomId.value, this.refs.eventType.value, content); - this.props.onFinished(true); - } catch (e) { - this.props.onFinished(false); - const ErrorDialog = sdk.getComponent('dialogs.ErrorDialog'); - Modal.createDialog(ErrorDialog, { - title: 'Failed to send custom event', - description: e.toString(), - }); + state = { + message: null, + }; + + onBack() { + if (this.state.message) { + this.setState({ message: null }); + } else { + this.props.onBack(); } } + _buttons() { + return
+ + {!this.state.message && } +
; + } + + send(content) { + return MatrixClientPeg.get().sendEvent(this.props.roomId, this.refs.eventType.value, content); + } + + async _send() { + let message; + try { + const content = JSON.parse(this.refs.evContent.value); + await this.send(content); + message = 'Event sent!'; + } catch (e) { + message = 'Failed to send custom event.' + ` (${e.toString()})`; + } + this.setState({ message }); + } + render() { + if (this.state.message) { + return
+
+ {this.state.message} +
+ {this._buttons()} +
; + } + return
-
- -
-
- -
-
@@ -66,55 +88,32 @@ class SendCustomEvent extends React.Component {
-