Merge pull request #1832 from matrix-org/luke/delay-group-leave-or-join

Add 500ms delay to show `membershipBusy` for longer
This commit is contained in:
Luke Barnard 2018-04-10 16:05:54 +01:00 committed by GitHub
commit 1b01c30fce
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -670,8 +670,13 @@ export default React.createClass({
}); });
}, },
_onAcceptInviteClick: function() { _onAcceptInviteClick: async function() {
this.setState({membershipBusy: true}); this.setState({membershipBusy: true});
// Wait 500ms to prevent flashing. Do this before sending a request otherwise we risk the
// spinner disappearing after we have fetched new group data.
await Promise.delay(500);
this._groupStore.acceptGroupInvite().then(() => { this._groupStore.acceptGroupInvite().then(() => {
// don't reset membershipBusy here: wait for the membership change to come down the sync // don't reset membershipBusy here: wait for the membership change to come down the sync
}).catch((e) => { }).catch((e) => {
@ -684,8 +689,13 @@ export default React.createClass({
}); });
}, },
_onRejectInviteClick: function() { _onRejectInviteClick: async function() {
this.setState({membershipBusy: true}); this.setState({membershipBusy: true});
// Wait 500ms to prevent flashing. Do this before sending a request otherwise we risk the
// spinner disappearing after we have fetched new group data.
await Promise.delay(500);
this._groupStore.leaveGroup().then(() => { this._groupStore.leaveGroup().then(() => {
// don't reset membershipBusy here: wait for the membership change to come down the sync // don't reset membershipBusy here: wait for the membership change to come down the sync
}).catch((e) => { }).catch((e) => {
@ -698,9 +708,13 @@ export default React.createClass({
}); });
}, },
_onJoinClick: function() { _onJoinClick: async function() {
this.setState({membershipBusy: true}); this.setState({membershipBusy: true});
// Wait 500ms to prevent flashing. Do this before sending a request otherwise we risk the
// spinner disappearing after we have fetched new group data.
await Promise.delay(500);
this._groupStore.joinGroup().then(() => { this._groupStore.joinGroup().then(() => {
// don't reset membershipBusy here: wait for the membership change to come down the sync // don't reset membershipBusy here: wait for the membership change to come down the sync
}).catch((e) => { }).catch((e) => {
@ -720,10 +734,15 @@ export default React.createClass({
description: _t("Leave %(groupName)s?", {groupName: this.props.groupId}), description: _t("Leave %(groupName)s?", {groupName: this.props.groupId}),
button: _t("Leave"), button: _t("Leave"),
danger: true, danger: true,
onFinished: (confirmed) => { onFinished: async (confirmed) => {
if (!confirmed) return; if (!confirmed) return;
this.setState({membershipBusy: true}); this.setState({membershipBusy: true});
// Wait 500ms to prevent flashing. Do this before sending a request otherwise we risk the
// spinner disappearing after we have fetched new group data.
await Promise.delay(500);
this._groupStore.leaveGroup().then(() => { this._groupStore.leaveGroup().then(() => {
// don't reset membershipBusy here: wait for the membership change to come down the sync // don't reset membershipBusy here: wait for the membership change to come down the sync
}).catch((e) => { }).catch((e) => {