Fixing Duplicate tasks showing up after joining a challenge (#7787)

* fix: prevents double joining challenge by quickly hitting join button on challenge twice. fixes #7730

* Fixing client side parameter updates.
This commit is contained in:
Travis
2016-12-20 17:52:18 -08:00
committed by Keith Holliday
parent 92cbb4a07d
commit 55a8eef3e1
3 changed files with 8 additions and 3 deletions

View File

@@ -320,6 +320,7 @@ habitrpg.controller("ChallengesCtrl", ['$rootScope','$scope', 'Shared', 'User',
*/ */
$scope.join = function (challenge) { $scope.join = function (challenge) {
challenge._joiningInProgress = true;
Challenges.joinChallenge(challenge._id) Challenges.joinChallenge(challenge._id)
.then(function (response) { .then(function (response) {
User.user.challenges.push(challenge._id); User.user.challenges.push(challenge._id);
@@ -329,6 +330,7 @@ habitrpg.controller("ChallengesCtrl", ['$rootScope','$scope', 'Shared', 'User',
.then(function (response) { .then(function (response) {
var tasks = response.data.data; var tasks = response.data.data;
User.syncUserTasks(tasks); User.syncUserTasks(tasks);
challenge._joiningInProgress = false;
}); });
} }

View File

@@ -79,8 +79,11 @@ schema.methods.syncToUser = async function syncChallengeToUser (user) {
challenge.shortName = challenge.shortName || challenge.name; challenge.shortName = challenge.shortName || challenge.name;
// Add challenge to user.challenges // Add challenge to user.challenges
if (!_.contains(user.challenges, challenge._id)) user.challenges.push(challenge._id); if (!_.contains(user.challenges, challenge._id)) {
// using concat because mongoose's protection against concurrent array modification isn't working as expected.
// see https://github.com/HabitRPG/habitrpg/pull/7787#issuecomment-232972394
user.challenges = user.challenges.concat([challenge._id]);
}
// Sync tags // Sync tags
let userTags = user.tags; let userTags = user.tags;
let i = _.findIndex(userTags, {id: challenge._id}); let i = _.findIndex(userTags, {id: challenge._id});

View File

@@ -202,7 +202,7 @@ script(type='text/ng-template', id='partials/options.social.challenges.html')
a.btn.btn-sm.btn-danger(ng-show='isUserMemberOf(challenge)', ng-click='clickLeave(challenge, $event)') a.btn.btn-sm.btn-danger(ng-show='isUserMemberOf(challenge)', ng-click='clickLeave(challenge, $event)')
span.glyphicon.glyphicon-ban-circle span.glyphicon.glyphicon-ban-circle
=env.t('leave') =env.t('leave')
a.btn.btn-sm.btn-success(ng-hide='isUserMemberOf(challenge)', ng-click='join(challenge)') a.btn.btn-sm.btn-success(ng-hide='isUserMemberOf(challenge)', ng-click='join(challenge)', ng-disabled='challenge._joiningInProgress')
span.glyphicon.glyphicon-ok span.glyphicon.glyphicon-ok
=env.t('join') =env.t('join')
a.accordion-toggle(id="{{challenge._id}}" ng-click='toggle(challenge._id)') a.accordion-toggle(id="{{challenge._id}}" ng-click='toggle(challenge._id)')