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

Fix reviewer feedbacks (WIP) #25

Open
wants to merge 2 commits into
base: challenge-listing-part-1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions src/actions/auth.js

This file was deleted.

178 changes: 144 additions & 34 deletions src/actions/challenges.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,71 @@ async function doGetChallenges(filter) {
return service.getChallenges(filter);
}

async function getActiveChallenges(filter) {
const activeFilter = {
async function getAllActiveChallenges(filter) {
const BUCKET_ALL_ACTIVE_CHALLENGES = constants.FILTER_BUCKETS[0];
let page;

if (util.isDisplayingBucket(filter, BUCKET_ALL_ACTIVE_CHALLENGES)) {
page = filter.page;
} else {
page = 1;
}

const allActiveFilter = {
...util.createChallengeCriteria(filter),
...util.createActiveChallengeCriteria(),
...util.createAllActiveChallengeCriteria(),
page,
};
return doGetChallenges(activeFilter);
return doGetChallenges(allActiveFilter);
}

async function getOpenForRegistrationChallenges(filter) {
const BUCKET_OPEN_FOR_REGISTRATION = constants.FILTER_BUCKETS[1];
let page;

if (util.isDisplayingBucket(filter, BUCKET_OPEN_FOR_REGISTRATION)) {
page = filter.page;
} else {
page = 1;
}

const openForRegistrationFilter = {
...util.createChallengeCriteria(filter),
...util.createOpenForRegistrationChallengeCriteria(),
page,
};
return doGetChallenges(openForRegistrationFilter);
}

async function getPastChallenges(filter) {
const pastFilter = {
async function getClosedChallenges(filter) {
const BUCKET_CLOSED_CHALLENGES = constants.FILTER_BUCKETS[1];
let page;

if (util.isDisplayingBucket(filter, BUCKET_CLOSED_CHALLENGES)) {
page = filter.page;
} else {
page = 1;
}

const closedFilter = {
...util.createChallengeCriteria(filter),
...util.createPastChallengeCriteria(),
...util.createClosedChallengeCriteria(),
page,
};
return doGetChallenges(pastFilter);
return doGetChallenges(closedFilter);
}

async function getRecommendedChallenges(filter) {
let result = [];
result.meta = { total: 0 };

if (result.length === 0) {
const failbackFilter = { ...filter };
result = await getOpenForRegistrationChallenges(failbackFilter);
result.loadingRecommendedChallengesError = true;
}

return result;
}

function doFilterBySubSommunities(challenges) {
Expand All @@ -43,46 +86,113 @@ function doFilterByPrizeTo(challenges) {

async function getChallenges(filter, change) {
const FILTER_BUCKETS = constants.FILTER_BUCKETS;
let challenges;
let challengesFiltered;
let total;
let filterChange = change;

const getChallengesByBucket = async (f) => {
switch (f.bucket) {
case FILTER_BUCKETS[0]:
return getActiveChallenges(f);
case FILTER_BUCKETS[1]:
return getOpenForRegistrationChallenges(f);
case FILTER_BUCKETS[2]:
return getPastChallenges(f);
default:
return [];
}
const BUCKET_ALL_ACTIVE_CHALLENGES = FILTER_BUCKETS[0];
const BUCKET_OPEN_FOR_REGISTRATION = FILTER_BUCKETS[1];
const BUCKET_CLOSED_CHALLENGES = FILTER_BUCKETS[2];
const filterChange = change;
const bucket = filter.bucket;

const getChallengesByBuckets = async (f) => {
return FILTER_BUCKETS.includes(f.bucket)
? Promise.all([
getAllActiveChallenges(f),
f.recommended
? getRecommendedChallenges(f)
: getOpenForRegistrationChallenges(f),
getClosedChallenges(f),
])
: [[], [], []];
};

if (!filterChange) {
let [
allActiveChallenges,
openForRegistrationChallenges,
closedChallenges,
] = await getChallengesByBuckets(filter);
let challenges;
let openForRegistrationCount;
let total;
let loadingRecommendedChallengesError;

switch (bucket) {
case BUCKET_ALL_ACTIVE_CHALLENGES:
challenges = allActiveChallenges;
break;
case BUCKET_OPEN_FOR_REGISTRATION:
challenges = openForRegistrationChallenges;
break;
case BUCKET_CLOSED_CHALLENGES:
challenges = closedChallenges;
break;
}
openForRegistrationCount = openForRegistrationChallenges.meta.total;
total = challenges.meta.total;
loadingRecommendedChallengesError =
challenges.loadingRecommendedChallengesError;

return {
challenges,
total,
openForRegistrationCount,
loadingRecommendedChallengesError,
allActiveChallenges,
openForRegistrationChallenges,
closedChallenges,
};
}

if (!util.checkRequiredFilterAttributes(filter)) {
return { challenges: [], challengesFiltered: [], total: 0 };
}

if (!filterChange) {
const chs = await getChallengesByBucket(filter);
return { challenges: chs, challengesFiltered: chs, total: chs.meta.total };
}
let allActiveChallenges;
let openForRegistrationChallenges;
let closedChallenges;
let challenges;
let openForRegistrationCount;
let total;
let loadingRecommendedChallengesError;

if (util.shouldFetchChallenges(filterChange)) {
challenges = await getChallengesByBucket(filter);
[
allActiveChallenges,
openForRegistrationChallenges,
closedChallenges,
] = await getChallengesByBuckets(filter);
switch (bucket) {
case BUCKET_ALL_ACTIVE_CHALLENGES:
challenges = allActiveChallenges;
break;
case BUCKET_OPEN_FOR_REGISTRATION:
challenges = openForRegistrationChallenges;
break;
case BUCKET_CLOSED_CHALLENGES:
challenges = closedChallenges;
break;
}
}

challengesFiltered = challenges;
openForRegistrationCount = openForRegistrationChallenges.meta.total;
total = challenges.meta.total;
loadingRecommendedChallengesError =
challenges.loadingRecommendedChallengesError;

if (util.shouldFilterChallenges(filterChange)) {
challengesFiltered = doFilterBySubSommunities(challengesFiltered);
challengesFiltered = doFilterByPrizeFrom(challengesFiltered);
challengesFiltered = doFilterByPrizeTo(challengesFiltered);
challenges = doFilterBySubSommunities(challenges);
challenges = doFilterByPrizeFrom(challenges);
challenges = doFilterByPrizeTo(challenges);
}

return { challenges, challengesFiltered, total };
return {
challenges,
total,
openForRegistrationCount,
loadingRecommendedChallengesError,
allActiveChallenges,
openForRegistrationChallenges,
closedChallenges,
};
}

export default createActions({
Expand Down
5 changes: 5 additions & 0 deletions src/actions/filter.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import { createActions } from "redux-actions";

function restoreFilter(filter) {
return filter;
}

function updateFilter(partialUpdate) {
return partialUpdate;
}

export default createActions({
RESTORE_FILTER: restoreFilter,
UPDATE_FILTER: updateFilter,
});
10 changes: 10 additions & 0 deletions src/assets/icons/card-view.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions src/assets/icons/list-view.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/icons/not-found-recommended.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 14 additions & 1 deletion src/components/Button/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import PT from "prop-types";
import "./styles.scss";

const Button = ({ children, onClick }) => (
<button styleName="button" onClick={onClick}>
<button styleName="button" onClick={onClick} type="button">
{children}
</button>
);
Expand All @@ -14,4 +14,17 @@ Button.propTypes = {
onClick: PT.func,
};

const ButtonIcon = ({ children, onClick }) => (
<button styleName="button-icon" onClick={onClick} type="button">
{children}
</button>
);

ButtonIcon.propTypes = {
children: PT.node,
onClick: PT.func,
};

export { Button, ButtonIcon };

export default Button;
14 changes: 12 additions & 2 deletions src/components/Button/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,15 @@
background-color: $green;
}

.button-lg {}
.button-sm {}
.button-icon {
width: 32px;
height: 32px;
padding: 0;
line-height: 0;
text-align: center;
vertical-align: middle;
appearance: none;
background: none;
border: 0;
border-radius: 50%;
}
6 changes: 5 additions & 1 deletion src/components/Checkbox/index.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Checkbox component.
*/
import React, { useRef, useState } from "react";
import React, { useRef, useState, useEffect } from "react";
import PT from "prop-types";
import _ from "lodash";
import "./styles.scss";
Expand All @@ -22,6 +22,10 @@ function Checkbox({ checked, onChange, size, errorMsg }) {
_.debounce((q, cb) => cb(q), process.env.GUIKIT.DEBOUNCE_ON_CHANGE_TIME) // eslint-disable-line no-undef
).current;

useEffect(() => {
setCheckedInternal(checked);
}, [checked]);

return (
<label styleName={`container ${sizeStyle}`}>
<input
Expand Down
Loading