From 89780586ac052c463c0fae973d005a0f2f1bbe7a Mon Sep 17 00:00:00 2001 From: suppermancool Date: Fri, 3 May 2019 23:56:34 +0700 Subject: [PATCH 1/3] code 30090056 code 30090056 --- src/actions/challenge-listing.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/actions/challenge-listing.js b/src/actions/challenge-listing.js index ad872794..6011c2c9 100644 --- a/src/actions/challenge-listing.js +++ b/src/actions/challenge-listing.js @@ -191,10 +191,9 @@ function getActiveChallengesDone( user = decodeToken(tokenV3).handle; // Handle any errors on this endpoint so that the non-user specific challenges // will still be loaded. - calls.push(service.getUserChallenges(user, filter, { - limit: PAGE_SIZE, - offset: page * PAGE_SIZE, - }).catch(() => ({ challenges: [] }))); + calls.push(getAll( + params => service.getUserChallenges(user, filter, params).catch(() => ({ challenges: [] })), + )); } return Promise.all(calls).then(([ch, uch]) => { /* uch array contains challenges where the user is participating in From e95c91b693a7e1b90e6cba62bcfc56d8ad34930a Mon Sep 17 00:00:00 2001 From: suppermancool Date: Sat, 4 May 2019 00:00:24 +0700 Subject: [PATCH 2/3] update nap shot update nap shot --- __tests__/__snapshots__/index.js.snap | 3 +++ 1 file changed, 3 insertions(+) diff --git a/__tests__/__snapshots__/index.js.snap b/__tests__/__snapshots__/index.js.snap index e7ee51bc..0386661f 100644 --- a/__tests__/__snapshots__/index.js.snap +++ b/__tests__/__snapshots__/index.js.snap @@ -426,14 +426,17 @@ Object { "countReset": [Function], "debug": [Function], "dir": [Function], + "dirxml": [Function], "error": [Function], "group": [Function], "groupCollapsed": [Function], "groupEnd": [Function], "info": [Function], "log": [Function], + "table": [Function], "time": [Function], "timeEnd": [Function], + "timeLog": [Function], "trace": [Function], "warn": [Function], }, From c5828ccd2758438578783bd5d8b7eeee4fb1cc7b Mon Sep 17 00:00:00 2001 From: suppermancool Date: Sat, 4 May 2019 09:47:41 +0700 Subject: [PATCH 3/3] code 30090056 code 30090056 --- src/actions/challenge-listing.js | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/actions/challenge-listing.js b/src/actions/challenge-listing.js index 6011c2c9..2e9c0d08 100644 --- a/src/actions/challenge-listing.js +++ b/src/actions/challenge-listing.js @@ -191,31 +191,33 @@ function getActiveChallengesDone( user = decodeToken(tokenV3).handle; // Handle any errors on this endpoint so that the non-user specific challenges // will still be loaded. - calls.push(getAll( - params => service.getUserChallenges(user, filter, params).catch(() => ({ challenges: [] })), - )); + calls.push(service.getUserChallenges(user, filter, { + limit: PAGE_SIZE, + offset: page * PAGE_SIZE, + }).catch(() => ({ challenges: [] }))); } return Promise.all(calls).then(([ch, uch]) => { + let fullCH = ch; /* uch array contains challenges where the user is participating in * some role. The same challenge are already listed in res array, but they * are not attributed to the user there. This block of code marks user * challenges in an efficient way. */ if (uch) { const map = {}; - uch.challenges.forEach((item) => { map[item.id] = item; }); - ch.challenges.forEach((item) => { - if (map[item.id]) { - /* It is fine to reassing, as the array we modifying is created just - * above within the same function. */ - /* eslint-disable no-param-reassign */ - item.users[user] = true; - item.userDetails = map[item.id].userDetails; - /* eslint-enable no-param-reassign */ - } + uch.challenges.forEach((item) => { + map[item.id] = item; + /* eslint-disable no-param-reassign */ + item.users[user] = true; + item.userDetails = map[item.id].userDetails; + /* eslint-enable no-param-reassign */ }); } - let { challenges, meta } = ch; + if (uch) { + fullCH = uch; + } + let { challenges } = fullCH; + let { meta } = ch; // filter by date range and re-compute meta // we can safely remove the next two lines when backend support date range challenges = filterUtil.filterByDate(challenges, frontFilter);