Skip to content
This repository was archived by the owner on Mar 4, 2025. It is now read-only.

Commit 78d2508

Browse files
author
vikasrohit
committed
SUP-2231, New Empty States for Dashboard and Profile, SUP-2231, User has past challenges but not able to access the past challenges from dashboard as user do not have any active challenges.
-- Moved logic for checking participation into service. -- Reversed the call order for participation and actual data services to avoid extra calls in most of the cases.
1 parent a69264a commit 78d2508

File tree

3 files changed

+42
-34
lines changed

3 files changed

+42
-34
lines changed

app/my-challenges/my-challenges.controller.js

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,9 @@
4242
activate();
4343

4444
function activate() {
45-
_checkForParticipation().then(function() {
46-
vm.isCopilot = _.includes(userIdentity.roles, 'copilot');
47-
vm.myChallenges = [];
48-
changeFilter(vm.statusFilter);
49-
});
45+
vm.isCopilot = _.includes(userIdentity.roles, 'copilot');
46+
vm.myChallenges = [];
47+
changeFilter(vm.statusFilter);
5048
}
5149

5250
function changeView(view) {
@@ -85,10 +83,16 @@
8583
$q.all(promises)
8684
.then(function(data) {
8785
// data should be an array of 2 objects each with it's own array (2D array with metadata)
88-
vm.loading = CONSTANTS.STATE_READY;
8986

9087
vm.totalCount = _.sum(_.pluck(data, 'metadata.totalCount'));
9188
vm.myChallenges = vm.myChallenges.concat(_.union(data[0], data[1]));
89+
if (vm.totalCount === 0) {
90+
_checkForParticipation().then(function() {
91+
vm.loading = CONSTANTS.STATE_READY;
92+
});
93+
} else {
94+
vm.loading = CONSTANTS.STATE_READY;
95+
}
9296
})
9397
.catch(function(resp) {
9498
$log.error(resp);
@@ -146,16 +150,8 @@
146150
}
147151

148152
function _checkForParticipation() {
149-
var params = {
150-
limit: 1,
151-
offset: 0
152-
};
153-
return ChallengeService.getUserChallenges(vm.handle, params).then(function(challenges) {
154-
if (challenges.metadata.totalCount > 0) {
155-
vm.neverParticipated = false;
156-
} else {
157-
vm.neverParticipated = true;
158-
}
153+
return ChallengeService.checkChallengeParticipation(vm.handle, function(participated) {
154+
vm.neverParticipated = !participated;
159155
});
160156
}
161157
}

app/my-dashboard/my-challenges/my-challenges.controller.js

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@
2020

2121
function activate() {
2222
vm.myChallenges = [];
23-
_checkForParticipation().then(function() {
24-
getChallenges();
25-
});
23+
getChallenges();
2624
}
2725

2826
function getChallenges() {
@@ -47,15 +45,17 @@
4745

4846
if (!marathonMatches.length && !devDesignChallenges.length) {
4947
vm.userHasChallenges = false;
50-
vm.loading = false;
48+
_checkForParticipation().then(function() {
49+
vm.loading = false;
50+
});
5151

5252
} else {
5353
ChallengeService.processActiveDevDesignChallenges(devDesignChallenges);
5454
ChallengeService.processActiveMarathonMatches(marathonMatches);
5555
var userChallenges = marathonMatches.concat(devDesignChallenges);
5656

5757
userChallenges = _.sortBy(userChallenges, function(n) {
58-
return n.registrationEndDate
58+
return n.registrationEndDate;
5959
});
6060
vm.myChallenges = userChallenges.reverse().slice(0, 8);
6161
vm.userHasChallenges = true;
@@ -76,16 +76,8 @@
7676
}
7777

7878
function _checkForParticipation() {
79-
var params = {
80-
limit: 1,
81-
offset: 0
82-
};
83-
return ChallengeService.getUserChallenges(handle, params).then(function(challenges) {
84-
if (challenges.metadata.totalCount > 0) {
85-
vm.neverParticipated = true;
86-
} else {
87-
vm.neverParticipated = true;
88-
}
79+
return ChallengeService.checkChallengeParticipation(handle, function(participated) {
80+
vm.neverParticipated = !participated;
8981
});
9082
}
9183
}

app/services/challenge.service.js

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33

44
angular.module('tc.services').factory('ChallengeService', ChallengeService);
55

6-
ChallengeService.$inject = ['CONSTANTS', 'ApiService'];
6+
ChallengeService.$inject = ['CONSTANTS', 'ApiService', '$q'];
77

8-
function ChallengeService(CONSTANTS, ApiService) {
8+
function ChallengeService(CONSTANTS, ApiService, $q) {
99
var api = ApiService.restangularV3;
1010

1111
var service = {
@@ -18,7 +18,8 @@
1818
processActiveMarathonMatches: processActiveMarathonMatches,
1919
processPastMarathonMatch: processPastMarathonMatch,
2020
processPastSRM: processPastSRM,
21-
processPastChallenges: processPastChallenges
21+
processPastChallenges: processPastChallenges,
22+
checkChallengeParticipation: checkChallengeParticipation
2223
};
2324

2425
return service;
@@ -207,5 +208,24 @@
207208
}
208209
});
209210
}
211+
212+
function checkChallengeParticipation(handle, callback) {
213+
var params = {
214+
limit: 1,
215+
offset: 0
216+
};
217+
return $q.all([
218+
getUserMarathonMatches(handle, params),
219+
getUserChallenges(handle, params)
220+
]).then(function(data) {
221+
var mms = data[0];
222+
var challenges = data[1];
223+
if (challenges.metadata.totalCount > 0 || mms.metadata.totalCount > 0) {
224+
callback(true);
225+
} else {
226+
callback(false);
227+
}
228+
});
229+
}
210230
};
211231
})();

0 commit comments

Comments
 (0)