-
-
Notifications
You must be signed in to change notification settings - Fork 832
Better support for inviting multiple people #403
Changes from 7 commits
54b3638
4a6a9bd
020e4e1
b9f0b72
6b3b2e3
fa498eb
d6f7358
cab95f4
a58a627
806477d
f42d619
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,11 +25,12 @@ export default class MultiInviteDialog extends React.Component { | |
|
||
this._onCancel = this._onCancel.bind(this); | ||
this._startInviting = this._startInviting.bind(this); | ||
this._canceled = false; | ||
|
||
this.state = { | ||
busy: false, | ||
completionStates: [], // State of each address (invited or error) | ||
errorTexts: [], // Textual error per address | ||
completionStates: {}, // State of each address (invited or error) | ||
errorTexts: {}, // Textual error per address | ||
done: false, | ||
}; | ||
for (let i = 0; i < this.props.inputs.length; ++i) { | ||
|
@@ -41,20 +42,28 @@ export default class MultiInviteDialog extends React.Component { | |
} | ||
} | ||
|
||
componentWillUnmount() { | ||
this._unmounted = true; | ||
} | ||
|
||
_onCancel() { | ||
this._canceled = true; | ||
this.props.onFinished(false); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shouldn't this attempt to cancel the invite process? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Otherwise the invite process could go on for hours in the background? And react will get very sad about the attempts to update the state. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would, although this button isn't visible once you start inviting - it probably should be though. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't the close button visible? On 10 August 2016 18:38:55 BST, David Baker notifications@github.com wrote:
|
||
} | ||
|
||
_startInviting() { | ||
this.setState({ | ||
completionStates: [], | ||
busy: true, | ||
done: false, | ||
}); | ||
this._inviteMore(0); | ||
} | ||
|
||
_inviteMore(nextIndex) { | ||
if (this._canceled) { | ||
return; | ||
} | ||
|
||
if (nextIndex == this.props.inputs.length) { | ||
this.setState({ | ||
busy: false, | ||
|
@@ -67,7 +76,7 @@ export default class MultiInviteDialog extends React.Component { | |
|
||
// don't try to invite it if it's an invalid address | ||
// (it will already be marked as an error though, | ||
// so no need top do so again | ||
// so no need to do so again) | ||
if (getAddressType(input) === null) { | ||
this._inviteMore(nextIndex + 1); | ||
return; | ||
|
@@ -81,12 +90,16 @@ export default class MultiInviteDialog extends React.Component { | |
} | ||
|
||
inviteToRoom(this.props.roomId, input).then(() => { | ||
if (this._unmounted) { return; } | ||
|
||
this.setState((s) => { | ||
s.completionStates[nextIndex] = 'invited' | ||
return s; | ||
}); | ||
this._inviteMore(nextIndex + 1); | ||
}, (err) => { | ||
if (this._unmounted) { return; } | ||
|
||
let errorText; | ||
let fatal = false; | ||
if (err.errcode == 'M_FORBIDDEN') { | ||
|
@@ -115,16 +128,19 @@ export default class MultiInviteDialog extends React.Component { | |
} | ||
|
||
_getProgressIndicator() { | ||
const numErrors = this.state.completionStates.filter((s) => { | ||
return s == 'error'; | ||
}).length; | ||
let numErrors = 0; | ||
for (const k of Object.keys(this.state.completionStates)) { | ||
if (this.state.completionStates[k] == 'error') { | ||
++numErrors; | ||
} | ||
} | ||
let errorText; | ||
if (numErrors > 0) { | ||
const plural = numErrors > 1 ? 's' : ''; | ||
errorText = <span className="error">({numErrors} error{plural})</span> | ||
} | ||
return <span> | ||
{this.state.completionStates.length} / {this.props.inputs.length} {errorText} | ||
{Object.keys(this.state.completionStates).length} / {this.props.inputs.length} {errorText} | ||
</span>; | ||
} | ||
|
||
|
@@ -153,6 +169,7 @@ export default class MultiInviteDialog extends React.Component { | |
let controls = []; | ||
if (this.state.busy) { | ||
controls.push(<Spinner key="spinner" />); | ||
controls.push(<button key="cancel" onClick={this._onCancel}>Cancel</button>); | ||
controls.push(<span key="progr">{this._getProgressIndicator()}</span>); | ||
} else if (this.state.done) { | ||
controls.push( | ||
|
@@ -196,4 +213,6 @@ export default class MultiInviteDialog extends React.Component { | |
|
||
MultiInviteDialog.propTypes = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. missing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (Done) |
||
onFinished: React.PropTypes.func.isRequired, | ||
inputs: React.PropTypes.array.isRequired, | ||
roomId: React.PropTypes.string.isRequired, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -176,6 +176,39 @@ module.exports = React.createClass({ | |
}); | ||
}, | ||
|
||
_doInvite(address) { | ||
Invite.inviteToRoom(self.props.roomId, address).catch((err) => { | ||
if (err !== null) { | ||
console.error("Failed to invite: %s", JSON.stringify(err)); | ||
if (err.errcode == 'M_FORBIDDEN') { | ||
Modal.createDialog(ErrorDialog, { | ||
title: "Unable to Invite", | ||
description: "You do not have permission to invite people to this room." | ||
}); | ||
} else { | ||
Modal.createDialog(ErrorDialog, { | ||
title: "Server error whilst inviting", | ||
description: err.message | ||
}); | ||
} | ||
} | ||
}).finally(() => { | ||
self.setState({ | ||
inviting: false | ||
}); | ||
// XXX: hacky focus on the invite box | ||
setTimeout(function() { | ||
var inviteBox = document.getElementById("mx_SearchableEntityList_query"); | ||
if (inviteBox) { | ||
inviteBox.focus(); | ||
} | ||
}, 0); | ||
}).done(); | ||
self.setState({ | ||
inviting: true | ||
}); | ||
} | ||
|
||
onInvite: function(inputText) { | ||
var ErrorDialog = sdk.getComponent("dialogs.ErrorDialog"); | ||
var NeedToRegisterDialog = sdk.getComponent("dialogs.NeedToRegisterDialog"); | ||
|
@@ -247,39 +280,7 @@ module.exports = React.createClass({ | |
if (inputs.length == 1) { | ||
// for a single address, we just send the invite | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how about factoring this out to another method? |
||
promise.then(() => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. s/then/done/ |
||
return Invite.inviteToRoom(self.props.roomId, inputs[0]); | ||
}).catch((err) => { | ||
if (err !== null) { | ||
console.error("Failed to invite: %s", JSON.stringify(err)); | ||
if (err.errcode == 'M_FORBIDDEN') { | ||
Modal.createDialog(ErrorDialog, { | ||
title: "Unable to Invite", | ||
description: "You do not have permission to invite people to this room." | ||
}); | ||
} else { | ||
Modal.createDialog(ErrorDialog, { | ||
title: "Server error whilst inviting", | ||
description: err.message | ||
}); | ||
} | ||
} | ||
self.setState({ | ||
inviting: false | ||
}); | ||
}).finally(() => { | ||
self.setState({ | ||
inviting: false | ||
}); | ||
// XXX: hacky focus on the invite box | ||
setTimeout(function() { | ||
var inviteBox = document.getElementById("mx_SearchableEntityList_query"); | ||
if (inviteBox) { | ||
inviteBox.focus(); | ||
} | ||
}, 0); | ||
}).done(); | ||
self.setState({ | ||
inviting: true | ||
this.doInvite(inputs[0]); | ||
}); | ||
} else { | ||
// if there are several, display the confirmation/progress dialog | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we also be setting
_canceled
here? What happens if the user closes the dialog without clicking 'cancel'? I'm a bit confused about the difference between_unmounted
and_canceled
, and why we handle them differently in_inviteMore
. Perhaps some comments would help?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Point - it should definitely cancel if you dismiss the dialog so I've just made them the same variable.