Skip to content

Commit 97906ac

Browse files
committed
fix: sort by prize
1 parent 5bb5a1a commit 97906ac

File tree

3 files changed

+35
-14
lines changed

3 files changed

+35
-14
lines changed

src/shared/actions/challenge-listing/index.js

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ function getMyPastChallengesInit(uuid, page, frontFilter) {
184184
*/
185185
function getActiveChallengesDone(uuid, page, backendFilter, tokenV3, frontFilter = {}) {
186186
const { sorts } = frontFilter;
187+
const sortObj = SORT[sorts[BUCKETS.ONGOING]];
187188
const filter = {
188189
backendFilter,
189190
frontFilter: {
@@ -193,8 +194,8 @@ function getActiveChallengesDone(uuid, page, backendFilter, tokenV3, frontFilter
193194
registrationEndDateEnd: new Date().toISOString(),
194195
perPage: PAGE_SIZE,
195196
page: page + 1,
196-
sortBy: sorts[BUCKETS.ONGOING],
197-
sortOrder: SORT[sorts[BUCKETS.ONGOING]].order,
197+
sortBy: sortObj.field ? sortObj.field : sorts[BUCKETS.ONGOING],
198+
sortOrder: sortObj.order,
198199
},
199200
};
200201
delete filter.frontFilter.sorts;
@@ -245,7 +246,7 @@ function getActiveChallengesDone(uuid, page, backendFilter, tokenV3, frontFilter
245246
function getOpenForRegistrationChallengesDone(uuid, page, backendFilter,
246247
tokenV3, frontFilter = {}, recommended = false, handle) {
247248
const { sorts } = frontFilter;
248-
const sortOrder = SORT[sorts[BUCKETS.OPEN_FOR_REGISTRATION]];
249+
const sortObj = SORT[sorts[BUCKETS.OPEN_FOR_REGISTRATION]];
249250
const filter = {
250251
backendFilter,
251252
frontFilter: {
@@ -254,8 +255,8 @@ function getOpenForRegistrationChallengesDone(uuid, page, backendFilter,
254255
currentPhaseName: 'Registration',
255256
perPage: PAGE_SIZE,
256257
page: page + 1,
257-
sortBy: sorts[BUCKETS.OPEN_FOR_REGISTRATION],
258-
sortOrder: sortOrder ? sortOrder.order : 'asc',
258+
sortBy: sortObj && sortObj.field ? sortObj.field : sorts[BUCKETS.OPEN_FOR_REGISTRATION],
259+
sortOrder: sortObj ? sortObj.order : 'asc',
259260
},
260261
};
261262
delete filter.frontFilter.sorts;
@@ -280,6 +281,7 @@ function getOpenForRegistrationChallengesDone(uuid, page, backendFilter,
280281
function getMyChallengesDone(uuid, page, backendFilter, tokenV3, frontFilter = {}) {
281282
const userId = decodeToken(tokenV3).userId.toString();
282283
const { sorts } = frontFilter;
284+
const sortObj = SORT[sorts[BUCKETS.MY]];
283285
const filter = {
284286
backendFilter,
285287
frontFilter: {
@@ -288,8 +290,8 @@ function getMyChallengesDone(uuid, page, backendFilter, tokenV3, frontFilter = {
288290
memberId: userId,
289291
perPage: PAGE_SIZE,
290292
page: page + 1,
291-
sortBy: sorts[BUCKETS.MY],
292-
sortOrder: SORT[sorts[BUCKETS.MY]].order,
293+
sortBy: sortObj.field ? sortObj.field : sorts[BUCKETS.MY],
294+
sortOrder: sortObj.order,
293295
},
294296
};
295297
delete filter.frontFilter.sorts;
@@ -304,15 +306,16 @@ function getMyChallengesDone(uuid, page, backendFilter, tokenV3, frontFilter = {
304306

305307
function getAllChallengesDone(uuid, page, backendFilter, tokenV3, frontFilter = {}) {
306308
const { sorts } = frontFilter;
309+
const sortObj = SORT[sorts[BUCKETS.ALL]];
307310
const filter = {
308311
backendFilter,
309312
frontFilter: {
310313
...frontFilter,
311314
status: 'Active',
312315
perPage: PAGE_SIZE,
313316
page: page + 1,
314-
sortBy: sorts[BUCKETS.ALL],
315-
sortOrder: SORT[sorts[BUCKETS.ALL]].order,
317+
sortBy: sortObj.field ? sortObj.field : sorts[BUCKETS.ALL],
318+
sortOrder: sortObj.order,
316319
},
317320
};
318321
delete filter.frontFilter.sorts;
@@ -328,6 +331,7 @@ function getAllChallengesDone(uuid, page, backendFilter, tokenV3, frontFilter =
328331
function getMyPastChallengesDone(uuid, page, backendFilter, tokenV3, frontFilter = {}) {
329332
const userId = decodeToken(tokenV3).userId.toString();
330333
const { sorts } = frontFilter;
334+
const sortObj = SORT[sorts[BUCKETS.MY_PAST]];
331335
const filter = {
332336
backendFilter,
333337
frontFilter: {
@@ -336,8 +340,8 @@ function getMyPastChallengesDone(uuid, page, backendFilter, tokenV3, frontFilter
336340
memberId: userId,
337341
perPage: PAGE_SIZE,
338342
page: page + 1,
339-
sortBy: sorts[BUCKETS.MY_PAST],
340-
sortOrder: SORT[sorts[BUCKETS.MY_PAST]].order,
343+
sortBy: sortObj.field ? sortObj.field : sorts[BUCKETS.MY_PAST],
344+
sortOrder: sortObj.order,
341345
},
342346
};
343347
delete filter.frontFilter.sorts;
@@ -436,15 +440,16 @@ function getPastChallengesInit(uuid, page, frontFilter) {
436440
*/
437441
function getPastChallengesDone(uuid, page, backendFilter, tokenV3, frontFilter = {}) {
438442
const { sorts } = frontFilter;
443+
const sortObj = SORT[sorts[BUCKETS.ALL_PAST]];
439444
const filter = {
440445
backendFilter,
441446
frontFilter: {
442447
...frontFilter,
443448
status: 'Completed',
444449
perPage: PAGE_SIZE,
445450
page: page + 1,
446-
sortBy: sorts[BUCKETS.ALL_PAST],
447-
sortOrder: SORT[sorts[BUCKETS.ALL_PAST]].order,
451+
sortBy: sortObj.field ? sortObj.field : sorts[BUCKETS.ALL_PAST],
452+
sortOrder: sortObj.order,
448453
},
449454
};
450455
delete filter.frontFilter.sorts;
@@ -546,6 +551,7 @@ export default createActions({
546551
DROP_MY_CHALLENGES: _.noop,
547552
DROP_ALL_CHALLENGES: _.noop,
548553
DROP_PAST_CHALLENGES: _.noop,
554+
DROP_MY_PAST_CHALLENGES: _.noop,
549555
DROP_RECOMMENDED_CHALLENGES: _.noop,
550556

551557
// GET_ALL_ACTIVE_CHALLENGES_INIT: getAllActiveChallengesInit,

src/shared/utils/challenge-listing/buckets.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ export const BUCKET_DATA = {
3030
name: 'All Challenges',
3131
sorts: [
3232
SORTS.MOST_RECENT_START_DATE,
33+
SORTS.PRIZE_HIGH_TO_LOW,
34+
SORTS.PRIZE_LOW_TO_HIGH,
3335
SORTS.TITLE_A_TO_Z,
3436
],
3537
},
@@ -46,6 +48,7 @@ export const BUCKET_DATA = {
4648
// SORTS.NUM_REGISTRANTS,
4749
// SORTS.NUM_SUBMISSIONS,
4850
SORTS.PRIZE_HIGH_TO_LOW,
51+
SORTS.PRIZE_LOW_TO_HIGH,
4952
SORTS.TITLE_A_TO_Z,
5053
],
5154
},
@@ -65,6 +68,7 @@ export const BUCKET_DATA = {
6568
// SORTS.NUM_REGISTRANTS,
6669
// SORTS.NUM_SUBMISSIONS,
6770
SORTS.PRIZE_HIGH_TO_LOW,
71+
SORTS.PRIZE_LOW_TO_HIGH,
6872
SORTS.TITLE_A_TO_Z,
6973
],
7074
},
@@ -82,6 +86,7 @@ export const BUCKET_DATA = {
8286
SORTS.CURRENT_PHASE,
8387
SORTS.TITLE_A_TO_Z,
8488
SORTS.PRIZE_HIGH_TO_LOW,
89+
SORTS.PRIZE_LOW_TO_HIGH,
8590
],
8691
},
8792
[BUCKETS.UPCOMING]: {

src/shared/utils/challenge-listing/sort.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,16 @@ import { sumBy } from 'lodash';
77
import { calculateScore } from './helper';
88
// import { phaseStartDate, phaseEndDate } from './helper';
99

10+
const PRIZE = 'overview.totalPrizes';
11+
1012
export const SORTS = {
1113
CURRENT_PHASE: 'current-phase',
1214
MOST_RECENT: 'updated',
1315
MOST_RECENT_START_DATE: 'startDate',
1416
// NUM_REGISTRANTS: 'num-registrants',
1517
// NUM_SUBMISSIONS: 'num-submissions',
16-
PRIZE_HIGH_TO_LOW: 'overview.totalPrizes',
18+
PRIZE_HIGH_TO_LOW: 'overview.totalPrizes-high-to-low',
19+
PRIZE_LOW_TO_HIGH: 'overview.totalPrizes-low-to-high',
1720
// TIME_TO_REGISTER: 'registrationEndDate',
1821
// TIME_TO_SUBMIT: 'submissionEndDate',
1922
TITLE_A_TO_Z: 'name',
@@ -40,6 +43,13 @@ export default {
4043
func: (a, b) => b.totalPrize - a.totalPrize,
4144
name: 'Prize high to low',
4245
order: 'desc',
46+
field: PRIZE,
47+
},
48+
[SORTS.PRIZE_LOW_TO_HIGH]: {
49+
func: (a, b) => b.totalPrize - a.totalPrize,
50+
name: 'Prize low to high',
51+
order: 'asc',
52+
field: PRIZE,
4353
},
4454
// [SORTS.TIME_TO_REGISTER]: {
4555
// func: (a, b) => {

0 commit comments

Comments
 (0)