Synced challenge tasks after leave and join.

This commit is contained in:
Keith Holliday
2016-05-15 10:14:29 -05:00
parent fcc02b16c6
commit bda90fad68
2 changed files with 25 additions and 10 deletions
@@ -293,7 +293,12 @@ habitrpg.controller("ChallengesCtrl", ['$rootScope','$scope', 'Shared', 'User',
Challenges.joinChallenge(challenge._id)
.then(function (response) {
User.user.challenges.push(challenge._id);
_getChallenges()
_getChallenges();
return Tasks.getUserTasks();
})
.then(function (response) {
var tasks = response.data.data;
User.syncUserTasks(tasks);
});
}
@@ -305,7 +310,12 @@ habitrpg.controller("ChallengesCtrl", ['$rootScope','$scope', 'Shared', 'User',
.then(function (response) {
var index = User.user.challenges.indexOf($scope.selectedChal._id);
delete User.user.challenges[index];
_getChallenges()
_getChallenges();
return Tasks.getUserTasks();
})
.then(function (response) {
var tasks = response.data.data;
User.syncUserTasks(tasks);
});
}
$scope.popoverEl.popover('destroy');
+13 -8
View File
@@ -45,6 +45,16 @@ angular.module('habitrpg')
user._wrapped = false;
function syncUserTasks (tasks) {
user.habits = [];
user.todos = [];
user.dailys = [];
user.rewards = [];
tasks.forEach(function (element, index, array) {
user[element.type + 's'].push(element)
});
}
function sync() {
return $http({
method: "GET",
@@ -84,14 +94,7 @@ angular.module('habitrpg')
})
.then(function (response) {
var tasks = response.data.data;
user.habits = [];
user.todos = [];
user.dailys = [];
user.rewards = [];
tasks.forEach(function (element, index, array) {
user[element.type + 's'].push(element)
})
syncUserTasks(tasks);
save();
$rootScope.$emit('userSynced');
});
@@ -479,6 +482,8 @@ angular.module('habitrpg')
return sync();
},
syncUserTasks: syncUserTasks,
save: save,
settings: settings