From 17262ad80d4a7596c698f6c13caa2842903e36bc Mon Sep 17 00:00:00 2001 From: Pablo Saavedra Date: Mon, 8 May 2017 12:18:31 +0200 Subject: [PATCH 1/7] Added TextInputWithCheckbox dialog --- src/component-index.js | 2 + src/components/structures/MatrixChat.js | 15 ++- .../dialogs/TextInputWithCheckboxDialog.js | 108 ++++++++++++++++++ 3 files changed, 122 insertions(+), 3 deletions(-) create mode 100644 src/components/views/dialogs/TextInputWithCheckboxDialog.js diff --git a/src/component-index.js b/src/component-index.js index d6873c6dfd..ed538a6fcb 100644 --- a/src/component-index.js +++ b/src/component-index.js @@ -99,6 +99,8 @@ import views$dialogs$SetDisplayNameDialog from './components/views/dialogs/SetDi views$dialogs$SetDisplayNameDialog && (module.exports.components['views.dialogs.SetDisplayNameDialog'] = views$dialogs$SetDisplayNameDialog); import views$dialogs$TextInputDialog from './components/views/dialogs/TextInputDialog'; views$dialogs$TextInputDialog && (module.exports.components['views.dialogs.TextInputDialog'] = views$dialogs$TextInputDialog); +import views$dialogs$TextInputWithCheckboxDialog from './components/views/dialogs/TextInputWithCheckboxDialog'; +views$dialogs$TextInputWithCheckboxDialog && (module.exports.components['views.dialogs.TextInputWithCheckboxDialog'] = views$dialogs$TextInputWithCheckboxDialog); import views$dialogs$UnknownDeviceDialog from './components/views/dialogs/UnknownDeviceDialog'; views$dialogs$UnknownDeviceDialog && (module.exports.components['views.dialogs.UnknownDeviceDialog'] = views$dialogs$UnknownDeviceDialog); import views$elements$AccessibleButton from './components/views/elements/AccessibleButton'; diff --git a/src/components/structures/MatrixChat.js b/src/components/structures/MatrixChat.js index b449ff3094..d87ca203ce 100644 --- a/src/components/structures/MatrixChat.js +++ b/src/components/structures/MatrixChat.js @@ -191,6 +191,10 @@ module.exports = React.createClass({ return this.props.config.default_is_url || "https://vector.im"; }, + getDefaultFederate() { + return this.props.config.default_federate && true; + }, + componentWillMount: function() { SdkConfig.put(this.props.config); @@ -501,15 +505,20 @@ module.exports = React.createClass({ //this._setPage(PageTypes.CreateRoom); //this.notifyNewScreen('new'); - var TextInputDialog = sdk.getComponent("dialogs.TextInputDialog"); - Modal.createDialog(TextInputDialog, { + var TextInputWithCheckboxDialog = sdk.getComponent("dialogs.TextInputWithCheckboxDialog"); + Modal.createDialog(TextInputWithCheckboxDialog, { title: "Create Room", description: "Room name (optional)", button: "Create Room", - onFinished: (should_create, name) => { + check: this.getDefaultFederate(), + checkLabel: "Federate room in domain " + MatrixClientPeg.get().getDomain(), + onFinished: (should_create, name, isFederate) => { if (should_create) { const createOpts = {}; if (name) createOpts.name = name; + if (isFederate) { + createOpts.creation_content = {"m.federate": isFederate} + } createRoom({createOpts}).done(); } } diff --git a/src/components/views/dialogs/TextInputWithCheckboxDialog.js b/src/components/views/dialogs/TextInputWithCheckboxDialog.js new file mode 100644 index 0000000000..916de16af5 --- /dev/null +++ b/src/components/views/dialogs/TextInputWithCheckboxDialog.js @@ -0,0 +1,108 @@ +/* +Copyright 2015, 2016 OpenMarket Ltd + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +import React from 'react'; +import sdk from '../../../index'; + +export default React.createClass({ + displayName: 'TextInputWithCheckboxDialog', + propTypes: { + title: React.PropTypes.string, + description: React.PropTypes.oneOfType([ + React.PropTypes.element, + React.PropTypes.string, + ]), + value: React.PropTypes.string, + button: React.PropTypes.string, + focus: React.PropTypes.bool, + checkLabel: React.PropTypes.string, + check: React.PropTypes.bool, + onFinished: React.PropTypes.func.isRequired, + }, + + getDefaultProps: function() { + return { + title: "", + value: "", + description: "", + button: "OK", + focus: true, + checkLabel: "", + check: true, + }; + }, + + getInitialState: function() { + return { + isChecked: this.props.check, + }; + }, + + componentDidMount: function() { + if (this.props.focus) { + // Set the cursor at the end of the text input + this.refs.textinput.value = this.props.value; + } + }, + + onOk: function() { + this.props.onFinished(true, this.refs.textinput.value, this.state.isChecked); + }, + + onCancel: function() { + this.props.onFinished(false); + }, + + _onToggle: function(keyName, checkedValue, uncheckedValue, ev) { + console.log("Checkbox toggle: %s %s", keyName, ev.target.checked); + var state = {}; + state[keyName] = ev.target.checked ? checkedValue : uncheckedValue; + this.setState(state); + }, + + render: function() { + const BaseDialog = sdk.getComponent('views.dialogs.BaseDialog'); + return ( + +
+
+ +
+
+ +
+ +
+
+ + +
+
+ ); + }, +}); From 4b4b7302331b195e199e44bd2abddbf1a2c68b29 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Wed, 2 Aug 2017 13:41:26 +0100 Subject: [PATCH 2/7] fix and i18n the impl Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- src/components/structures/MatrixChat.js | 24 ++++++++------ .../dialogs/TextInputWithCheckboxDialog.js | 33 +++++++------------ src/i18n/strings/en_EN.json | 2 ++ 3 files changed, 27 insertions(+), 32 deletions(-) diff --git a/src/components/structures/MatrixChat.js b/src/components/structures/MatrixChat.js index 50ee9963a6..22119585d9 100644 --- a/src/components/structures/MatrixChat.js +++ b/src/components/structures/MatrixChat.js @@ -214,10 +214,6 @@ module.exports = React.createClass({ return this.props.config.default_is_url || "https://vector.im"; }, - getDefaultFederate() { - return this.props.config.default_federate && true; - }, - componentWillMount: function() { SdkConfig.put(this.props.config); @@ -790,19 +786,27 @@ module.exports = React.createClass({ dis.dispatch({action: 'view_set_mxid'}); return; } + // Dialog shows inverse of m.federate (noFederate) strict false check to skip undefined check (default = true) + const defaultNoFederate = this.props.config.default_federate === false; const TextInputWithCheckboxDialog = sdk.getComponent("dialogs.TextInputWithCheckboxDialog"); Modal.createDialog(TextInputWithCheckboxDialog, { title: _t('Create Room'), description: _t('Room name (optional)'), button: _t('Create Room'), - // TODO i18n below. - check: this.getDefaultFederate(), - checkLabel: 'Federate room in domain ' + MatrixClientPeg.get().getDomain(), - onFinished: (shouldCreate, name, federate) => { + check: defaultNoFederate, + checkLabel: + {_t('Block users on other matrix homeservers from joining this room')} +
+ ({_t('This setting cannot be changed later!')}) +
, + onFinished: (shouldCreate, name, noFederate) => { if (shouldCreate) { - const createOpts = {}; + const createOpts = { + creation_content: { + "m.federate": !noFederate, + }, + }; if (name) createOpts.name = name; - if (federate) createOpts.creation_content = {"m.federate": federate}; createRoom({createOpts}).done(); } }, diff --git a/src/components/views/dialogs/TextInputWithCheckboxDialog.js b/src/components/views/dialogs/TextInputWithCheckboxDialog.js index 916de16af5..613fab4cdb 100644 --- a/src/components/views/dialogs/TextInputWithCheckboxDialog.js +++ b/src/components/views/dialogs/TextInputWithCheckboxDialog.js @@ -16,6 +16,7 @@ limitations under the License. import React from 'react'; import sdk from '../../../index'; +import { _t } from '../../../languageHandler'; export default React.createClass({ displayName: 'TextInputWithCheckboxDialog', @@ -28,7 +29,10 @@ export default React.createClass({ value: React.PropTypes.string, button: React.PropTypes.string, focus: React.PropTypes.bool, - checkLabel: React.PropTypes.string, + checkLabel: React.PropTypes.oneOfType([ + React.PropTypes.element, + React.PropTypes.string, + ]), check: React.PropTypes.bool, onFinished: React.PropTypes.func.isRequired, }, @@ -38,16 +42,9 @@ export default React.createClass({ title: "", value: "", description: "", - button: "OK", focus: true, checkLabel: "", - check: true, - }; - }, - - getInitialState: function() { - return { - isChecked: this.props.check, + check: false, }; }, @@ -59,20 +56,13 @@ export default React.createClass({ }, onOk: function() { - this.props.onFinished(true, this.refs.textinput.value, this.state.isChecked); + this.props.onFinished(true, this.refs.textinput.value, this.refs.checkbox.value); }, onCancel: function() { this.props.onFinished(false); }, - _onToggle: function(keyName, checkedValue, uncheckedValue, ev) { - console.log("Checkbox toggle: %s %s", keyName, ev.target.checked); - var state = {}; - state[keyName] = ev.target.checked ? checkedValue : uncheckedValue; - this.setState(state); - }, - render: function() { const BaseDialog = sdk.getComponent('views.dialogs.BaseDialog'); return ( @@ -87,16 +77,15 @@ export default React.createClass({
+
diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index 87eb189ad0..f7fb221072 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -146,6 +146,7 @@ "Microphone": "Microphone", "Camera": "Camera", "Advanced": "Advanced", + "Advanced options": "Advanced options", "Algorithm": "Algorithm", "Hide removed messages": "Hide removed messages", "Always show message timestamps": "Always show message timestamps", From 38de4ae1524bb34e3d54b0c12f802ac2f4c95097 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Thu, 5 Oct 2017 08:00:22 +0100 Subject: [PATCH 6/7] delint Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- src/components/views/dialogs/CreateRoomDialog.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/components/views/dialogs/CreateRoomDialog.js b/src/components/views/dialogs/CreateRoomDialog.js index 20eeb5b591..d5a99dd4bf 100644 --- a/src/components/views/dialogs/CreateRoomDialog.js +++ b/src/components/views/dialogs/CreateRoomDialog.js @@ -48,21 +48,21 @@ export default React.createClass({ >
- +
- +
-
+
{ _t('Advanced options') }
- +
From c115980f21c83c598786f4deed375a1b469b6b53 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Thu, 5 Oct 2017 08:08:39 +0100 Subject: [PATCH 7/7] remove redundant&stale onKeyDown Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- src/components/views/dialogs/CreateRoomDialog.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/views/dialogs/CreateRoomDialog.js b/src/components/views/dialogs/CreateRoomDialog.js index d5a99dd4bf..f7be47b3eb 100644 --- a/src/components/views/dialogs/CreateRoomDialog.js +++ b/src/components/views/dialogs/CreateRoomDialog.js @@ -51,7 +51,7 @@ export default React.createClass({
- +