prototype status filter

This commit is contained in:
Mateusz Tylka 2023-04-14 15:55:05 +02:00
parent 94292c75e3
commit cfc340c4f1
2 changed files with 18 additions and 23 deletions

View File

@ -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>

View File

@ -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;