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(() => { React.useEffect(() => {
statusFilter(status, challengesFromAPI, setChallenges); statusFilter(status, challengesFromAPI, challenges, setChallenges);
// eslint-disable-next-line react-hooks/exhaustive-deps // eslint-disable-next-line react-hooks/exhaustive-deps
}, [status]); }, [status]);
@ -82,21 +82,9 @@ const Challenges = () => {
<> <>
{filtersMenuRender( {filtersMenuRender(
filtersMenu ? '0' : '100vw', 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"> <ChallengesStyle as="main" id="start">
<FlexColumn className="ChallengesStyle__page-container"> <FlexColumn className="ChallengesStyle__page-container">
<H1 as="h1">Challenges</H1> <H1 as="h1">Challenges</H1>

View File

@ -19,8 +19,13 @@ const getDeadlineTime = (deadline) => {
} }
}; };
const statusFilter = (status, challenges, setChallenges) => { const statusFilter = (
let result = challenges; status,
challengesAll,
challengesToRender,
setChallenges
) => {
let result = challengesAll;
const date = new Date(); const date = new Date();
const currentDate = { const currentDate = {
year: date.getFullYear(), year: date.getFullYear(),
@ -29,28 +34,30 @@ const statusFilter = (status, challenges, setChallenges) => {
}; };
switch (status) { switch (status) {
case CHALLENGES_STATUS_FILTER.CLOSED: case CHALLENGES_STATUS_FILTER.CLOSED:
result = challenges.filter((challenge) => result = challengesAll.filter((challenge) =>
dateIsOlder( dateIsOlder(
currentDate, currentDate,
challenge.deadline ? getDeadlineTime(challenge.deadline) : false challenge.deadline ? getDeadlineTime(challenge.deadline) : false
) )
); );
setChallenges(result);
break; break;
case CHALLENGES_STATUS_FILTER.ACTIVE: case CHALLENGES_STATUS_FILTER.ACTIVE:
result = challenges.filter( result = challengesAll.filter(
(challenge) => (challenge) =>
!dateIsOlder( !dateIsOlder(
currentDate, currentDate,
challenge.deadline ? getDeadlineTime(challenge.deadline) : true challenge.deadline ? getDeadlineTime(challenge.deadline) : false
) )
); );
setChallenges(result);
break; break;
default: default:
setChallenges(challenges); result = challengesAll;
break; break;
} }
// result = result.filter((elem) => {
// return !challengesToRender.includes(elem);
// });
setChallenges(result);
}; };
export default statusFilter; export default statusFilter;