Handle onPaste AddressPickerDialog, allow addressing CSV/NL/Space delim list

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
Michael Telatynski 2019-07-25 21:45:32 +01:00
parent cef67d5784
commit c9e1c68726

View file

@ -1,6 +1,7 @@
/* /*
Copyright 2015, 2016 OpenMarket Ltd Copyright 2015, 2016 OpenMarket Ltd
Copyright 2017, 2018, 2019 New Vector Ltd Copyright 2017, 2018, 2019 New Vector Ltd
Copyright 2019 Michael Telatynski <7t3chguy@gmail.com>
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
@ -102,7 +103,7 @@ module.exports = React.createClass({
// Check the text input field to see if user has an unconverted address // Check the text input field to see if user has an unconverted address
// If there is and it's valid add it to the local selectedList // If there is and it's valid add it to the local selectedList
if (this.refs.textinput.value !== '') { if (this.refs.textinput.value !== '') {
selectedList = this._addInputToList(); selectedList = this._addAddressesToList([this.refs.textinput.value]);
if (selectedList === null) return; if (selectedList === null) return;
} }
this.props.onFinished(true, selectedList); this.props.onFinished(true, selectedList);
@ -140,12 +141,12 @@ module.exports = React.createClass({
// if there's nothing in the input box, submit the form // if there's nothing in the input box, submit the form
this.onButtonClick(); this.onButtonClick();
} else { } else {
this._addInputToList(); this._addAddressesToList([this.refs.textinput.value]);
} }
} else if (e.keyCode === 188 || e.keyCode === 9) { // comma or tab } else if (e.keyCode === 188 || e.keyCode === 9) { // comma or tab
e.stopPropagation(); e.stopPropagation();
e.preventDefault(); e.preventDefault();
this._addInputToList(); this._addAddressesToList([this.refs.textinput.value]);
} }
}, },
@ -453,14 +454,18 @@ module.exports = React.createClass({
}); });
}, },
_addInputToList: function() { _addAddressesToList: function(addressTexts) {
const addressText = this.refs.textinput.value.trim(); const selectedList = this.state.selectedList.slice();
addressTexts.forEach((addressText) => {
addressText = addressText.trim();
const addrType = getAddressType(addressText); const addrType = getAddressType(addressText);
const addrObj = { const addrObj = {
addressType: addrType, addressType: addrType,
address: addressText, address: addressText,
isKnown: false, isKnown: false,
}; };
if (!this.props.validAddressTypes.includes(addrType)) { if (!this.props.validAddressTypes.includes(addrType)) {
this.setState({ error: true }); this.setState({ error: true });
return null; return null;
@ -480,8 +485,9 @@ module.exports = React.createClass({
} }
} }
const selectedList = this.state.selectedList.slice();
selectedList.push(addrObj); selectedList.push(addrObj);
});
this.setState({ this.setState({
selectedList, selectedList,
suggestedList: [], suggestedList: [],
@ -540,6 +546,12 @@ module.exports = React.createClass({
}); });
}, },
_onPaste: function(e) {
const text = e.clipboardData.getData("text");
this._addAddressesToList(text.split(/[\s,]+/));
e.preventDefault();
},
render: function() { render: function() {
const BaseDialog = sdk.getComponent('views.dialogs.BaseDialog'); const BaseDialog = sdk.getComponent('views.dialogs.BaseDialog');
const DialogButtons = sdk.getComponent('views.elements.DialogButtons'); const DialogButtons = sdk.getComponent('views.elements.DialogButtons');
@ -564,7 +576,9 @@ module.exports = React.createClass({
// Add the query at the end // Add the query at the end
query.push( query.push(
<textarea key={this.state.selectedList.length} <textarea
key={this.state.selectedList.length}
onPaste={this._onPaste}
rows="1" rows="1"
id="textinput" id="textinput"
ref="textinput" ref="textinput"