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 1 commit
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
Prev Previous commit
fixed issue that daterangepicker not editable
fixed issue that prize amount missing 'USD' suffix
fixed issue that dropdownTerms missing small size
updated lint-fix
  • Loading branch information
nqviet committed Apr 5, 2021
commit a65a4d10deeb7958430385f081c3cf3049a3c783
127 changes: 104 additions & 23 deletions src/actions/challenges.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,69 @@ async function doGetChallenges(filter) {
}

async function getAllActiveChallenges(filter) {
const activeFilter = {
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.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 getClosedChallenges(filter) {
const pastFilter = {
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.createClosedChallengeCriteria(),
page,
};
return doGetChallenges(pastFilter);
return doGetChallenges(closedFilter);
}

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

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

return result;
}

Expand All @@ -51,35 +88,58 @@ async function getChallenges(filter, change) {
const FILTER_BUCKETS = constants.FILTER_BUCKETS;
const BUCKET_ALL_ACTIVE_CHALLENGES = FILTER_BUCKETS[0];
const BUCKET_OPEN_FOR_REGISTRATION = FILTER_BUCKETS[1];
const BUCKET_PAST_CHALLENGES = FILTER_BUCKETS[2];
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() : getOpenForRegistrationChallenges(f),
getClosedChallenges(f)
])
: [[], [], []]
getAllActiveChallenges(f),
f.recommended
? getRecommendedChallenges(f)
: getOpenForRegistrationChallenges(f),
getClosedChallenges(f),
])
: [[], [], []];
};

if (!filterChange) {
let [allActiveChallenges, openForRegistrationChallenges, closedChallenges] = await getChallengesByBuckets(filter)
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_PAST_CHALLENGES: challenges = closedChallenges; break;
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;

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

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

if (!util.checkRequiredFilterAttributes(filter)) {
Expand All @@ -92,26 +152,47 @@ async function getChallenges(filter, change) {
let challenges;
let openForRegistrationCount;
let total;
let loadingRecommendedChallengesError;

if (util.shouldFetchChallenges(filterChange)) {
[allActiveChallenges, openForRegistrationChallenges, closedChallenges] = await getChallengesByBuckets(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_PAST_CHALLENGES: challenges = closedChallenges; break;
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;

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

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

export default createActions({
Expand Down
2 changes: 1 addition & 1 deletion src/actions/filter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createActions } from "redux-actions";

function restoreFilter (filter) {
function restoreFilter(filter) {
return filter;
}

Expand Down
7 changes: 2 additions & 5 deletions src/components/Button/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,13 @@ 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 { Button, ButtonIcon };

export default Button;
4 changes: 2 additions & 2 deletions src/components/Checkbox/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ function Checkbox({ checked, onChange, size, errorMsg }) {
).current;

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

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