Factor out adding the input field to the list

This commit is contained in:
David Baker 2017-01-19 17:03:16 +00:00
parent ee1f6c772e
commit a2ff1cd8e6

View file

@ -71,15 +71,12 @@ module.exports = React.createClass({
}, },
onButtonClick: function() { onButtonClick: function() {
var inviteList = this.state.inviteList.slice(); let inviteList = this.state.inviteList.slice();
// 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 inviteList // If there is and it's valid add it to the local inviteList
const addrType = Invite.getAddressType(this.refs.textinput.value); if (this.refs.textinput.value !== '') {
if (addrType !== null) { inviteList = this._addInputToList();
inviteList.push(this.refs.textinput.value); if (inviteList === false) return;
} else if (this.refs.textinput.value.length > 0) {
this.setState({ error: true });
return;
} }
if (inviteList.length > 0) { if (inviteList.length > 0) {
@ -139,32 +136,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 {
const addrType = Invite.getAddressType(this.refs.textinput.value); this._addInputToList();
if (addrType !== null) {
const inviteList = this.state.inviteList.slice();
inviteList.push(this.refs.textinput.value.trim());
this.setState({
inviteList: inviteList,
queryList: [],
});
} else {
this.setState({ error: true });
}
} }
} 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();
const addrType = Invite.getAddressType(this.refs.textinput.value); this._addInputToList();
if (addrType !== null) {
var inviteList = this.state.inviteList.slice();
inviteList.push(this.refs.textinput.value.trim());
this.setState({
inviteList: inviteList,
queryList: [],
});
} else {
this.setState({ error: true });
}
} }
}, },
@ -376,6 +353,22 @@ module.exports = React.createClass({
return addrs; return addrs;
}, },
_addInputToList: function() {
const addrType = Invite.getAddressType(this.refs.textinput.value);
if (addrType !== null) {
const inviteList = this.state.inviteList.slice();
inviteList.push(this.refs.textinput.value.trim());
this.setState({
inviteList: inviteList,
queryList: [],
});
return inviteList;
} else {
this.setState({ error: true });
return false;
}
},
render: function() { render: function() {
var TintableSvg = sdk.getComponent("elements.TintableSvg"); var TintableSvg = sdk.getComponent("elements.TintableSvg");
var AddressSelector = sdk.getComponent("elements.AddressSelector"); var AddressSelector = sdk.getComponent("elements.AddressSelector");