Skip to content

Commit ea9c3e3

Browse files
author
Huan Li
committed
Fixed issues of server-side filtering on challenge listings
1 parent dbabfda commit ea9c3e3

File tree

2 files changed

+35
-18
lines changed

2 files changed

+35
-18
lines changed

src/actions/challenge-listing.js

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,11 @@ function getAllActiveChallengesDone(uuid, tokenV3) {
150150
});
151151
}
152152

153-
return { uuid, challenges: ch.challenges };
153+
return {
154+
uuid,
155+
challenges: ch.challenges,
156+
handle: user,
157+
};
154158
});
155159
}
156160

@@ -197,27 +201,27 @@ function getActiveChallengesDone(
197201
}).catch(() => ({ challenges: [] })));
198202
}
199203
return Promise.all(calls).then(([ch, uch]) => {
200-
let fullCH = ch;
204+
// let fullCH = ch;
201205
/* uch array contains challenges where the user is participating in
202206
* some role. The same challenge are already listed in res array, but they
203207
* are not attributed to the user there. This block of code marks user
204208
* challenges in an efficient way. */
205209
if (uch) {
206210
const map = {};
207-
uch.challenges.forEach((item) => {
208-
map[item.id] = item;
209-
/* eslint-disable no-param-reassign */
210-
item.users[user] = true;
211-
item.userDetails = map[item.id].userDetails;
212-
/* eslint-enable no-param-reassign */
211+
uch.challenges.forEach((item) => { map[item.id] = item; });
212+
ch.challenges.forEach((item) => {
213+
if (map[item.id]) {
214+
/* It is fine to reassing, as the array we modifying is created just
215+
* above within the same function. */
216+
/* eslint-disable no-param-reassign */
217+
item.users[user] = true;
218+
item.userDetails = map[item.id].userDetails;
219+
/* eslint-enable no-param-reassign */
220+
}
213221
});
214222
}
215223

216-
if (uch) {
217-
fullCH = uch;
218-
}
219-
let { challenges } = fullCH;
220-
let { meta } = ch;
224+
let { challenges, meta } = ch;
221225
// filter by date range and re-compute meta
222226
// we can safely remove the next two lines when backend support date range
223227
challenges = filterUtil.filterByDate(challenges, frontFilter);

src/reducers/challenge-listing.js

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,20 +94,33 @@ function onGetAllActiveChallengesDone(state, { error, payload }) {
9494
logger.error(payload);
9595
return state;
9696
}
97-
const { uuid, challenges: loaded } = payload;
97+
const {
98+
uuid, challenges: loaded, handle,
99+
} = payload;
98100
if (uuid !== state.loadingActiveChallengesUUID) return state;
99101
/* Once all active challenges are fetched from the API, we remove from the
100102
* store any active challenges stored there previously, and also any
101103
* challenges with IDs matching any challenges loaded now as active. */
102104
const ids = new Set();
103105
loaded.forEach(item => ids.add(item.id));
104-
const challenges = state.challenges
105-
.filter(item => item.status !== 'ACTIVE' && !ids.has(item.id))
106-
.concat(loaded);
106+
107+
const filter = item => !ids.has(item.id) && item.status !== 'ACTIVE';
108+
// BUCKET.MY
109+
const my = processBucketData(
110+
handle, state.challenges, loaded, BUCKETS.MY, null, null, filter, {},
111+
);
112+
// BUCKET.ALL
113+
const all = processBucketData(
114+
handle, state.challenges, loaded, BUCKETS.ALL, null, null, filter, {},
115+
);
116+
117+
const newChallenges = _.cloneDeep(state.challenges);
118+
newChallenges[BUCKETS.ALL] = all;
119+
newChallenges[BUCKETS.MY] = my;
107120

108121
return {
109122
...state,
110-
challenges,
123+
challenges: newChallenges,
111124
lastUpdateOfActiveChallenges: Date.now(),
112125
loadingActiveChallengesUUID: '',
113126
};

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy