mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 07:07:35 +01:00
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:
@@ -320,6 +320,7 @@ habitrpg.controller("ChallengesCtrl", ['$rootScope','$scope', 'Shared', 'User',
|
||||
*/
|
||||
|
||||
$scope.join = function (challenge) {
|
||||
challenge._joiningInProgress = true;
|
||||
Challenges.joinChallenge(challenge._id)
|
||||
.then(function (response) {
|
||||
User.user.challenges.push(challenge._id);
|
||||
@@ -329,6 +330,7 @@ habitrpg.controller("ChallengesCtrl", ['$rootScope','$scope', 'Shared', 'User',
|
||||
.then(function (response) {
|
||||
var tasks = response.data.data;
|
||||
User.syncUserTasks(tasks);
|
||||
challenge._joiningInProgress = false;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -79,8 +79,11 @@ schema.methods.syncToUser = async function syncChallengeToUser (user) {
|
||||
challenge.shortName = challenge.shortName || challenge.name;
|
||||
|
||||
// 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
|
||||
let userTags = user.tags;
|
||||
let i = _.findIndex(userTags, {id: challenge._id});
|
||||
|
||||
@@ -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)')
|
||||
span.glyphicon.glyphicon-ban-circle
|
||||
=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
|
||||
=env.t('join')
|
||||
a.accordion-toggle(id="{{challenge._id}}" ng-click='toggle(challenge._id)')
|
||||
|
||||
Reference in New Issue
Block a user