prototype status filter
This commit is contained in:
parent
94292c75e3
commit
cfc340c4f1
@ -31,7 +31,7 @@ const Challenges = () => {
|
||||
}, []);
|
||||
|
||||
React.useEffect(() => {
|
||||
statusFilter(status, challengesFromAPI, setChallenges);
|
||||
statusFilter(status, challengesFromAPI, challenges, setChallenges);
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [status]);
|
||||
|
||||
@ -82,21 +82,9 @@ const Challenges = () => {
|
||||
<>
|
||||
{filtersMenuRender(
|
||||
filtersMenu ? '0' : '100vw',
|
||||
filtersMenu ? '1' : '0'
|
||||
filtersMenu ? '1' : '0',
|
||||
'flex'
|
||||
)}
|
||||
<FiltersMenu
|
||||
toggleFiltersMenu={toggleFiltersMenu}
|
||||
sortByHandler={setSortBy}
|
||||
statusHandler={setStatus}
|
||||
challengeTypeHandler={setChallengeType}
|
||||
commercialHandler={setCommercial}
|
||||
sortBy={sortBy}
|
||||
status={status}
|
||||
challengeType={challengeType}
|
||||
commercial={commercial}
|
||||
translateX={filtersMenu ? '0' : '100vw'}
|
||||
opacity={filtersMenu ? '1' : '0'}
|
||||
/>
|
||||
<ChallengesStyle as="main" id="start">
|
||||
<FlexColumn className="ChallengesStyle__page-container">
|
||||
<H1 as="h1">Challenges</H1>
|
||||
|
@ -19,8 +19,13 @@ const getDeadlineTime = (deadline) => {
|
||||
}
|
||||
};
|
||||
|
||||
const statusFilter = (status, challenges, setChallenges) => {
|
||||
let result = challenges;
|
||||
const statusFilter = (
|
||||
status,
|
||||
challengesAll,
|
||||
challengesToRender,
|
||||
setChallenges
|
||||
) => {
|
||||
let result = challengesAll;
|
||||
const date = new Date();
|
||||
const currentDate = {
|
||||
year: date.getFullYear(),
|
||||
@ -29,28 +34,30 @@ const statusFilter = (status, challenges, setChallenges) => {
|
||||
};
|
||||
switch (status) {
|
||||
case CHALLENGES_STATUS_FILTER.CLOSED:
|
||||
result = challenges.filter((challenge) =>
|
||||
result = challengesAll.filter((challenge) =>
|
||||
dateIsOlder(
|
||||
currentDate,
|
||||
challenge.deadline ? getDeadlineTime(challenge.deadline) : false
|
||||
)
|
||||
);
|
||||
setChallenges(result);
|
||||
break;
|
||||
case CHALLENGES_STATUS_FILTER.ACTIVE:
|
||||
result = challenges.filter(
|
||||
result = challengesAll.filter(
|
||||
(challenge) =>
|
||||
!dateIsOlder(
|
||||
currentDate,
|
||||
challenge.deadline ? getDeadlineTime(challenge.deadline) : true
|
||||
challenge.deadline ? getDeadlineTime(challenge.deadline) : false
|
||||
)
|
||||
);
|
||||
setChallenges(result);
|
||||
break;
|
||||
default:
|
||||
setChallenges(challenges);
|
||||
result = challengesAll;
|
||||
break;
|
||||
}
|
||||
// result = result.filter((elem) => {
|
||||
// return !challengesToRender.includes(elem);
|
||||
// });
|
||||
setChallenges(result);
|
||||
};
|
||||
|
||||
export default statusFilter;
|
||||
|
Loading…
Reference in New Issue
Block a user