From 94292c75e3cc0ea30e24d023fc9417101df661e7 Mon Sep 17 00:00:00 2001 From: Mateusz Tylka Date: Fri, 14 Apr 2023 15:25:49 +0200 Subject: [PATCH] resolve merge conflict --- .../AllEntries/AllEntries.js | 9 ++-- src/pages/Challanges/Challenges.js | 5 +- src/pages/Challanges/statusFilter.js | 51 +++++++++++++++++++ 3 files changed, 57 insertions(+), 8 deletions(-) diff --git a/src/components/specific_challenge/AllEntries/AllEntries.js b/src/components/specific_challenge/AllEntries/AllEntries.js index d5661f0..cb5d7a7 100644 --- a/src/components/specific_challenge/AllEntries/AllEntries.js +++ b/src/components/specific_challenge/AllEntries/AllEntries.js @@ -6,9 +6,8 @@ import { H2 } from '../../../utils/fonts'; import { CALC_PAGES, EVALUATIONS_FORMAT, - RENDER_WHEN - IS_MOBILE, RENDER_WHEN, + IS_MOBILE, } from '../../../utils/globals'; import Loading from '../../generic/Loading'; import Pager from '../../generic/Pager'; @@ -69,8 +68,6 @@ const AllEntries = (props) => { allEntriesSearchQueryHandler(event, entriesAll, setPageNr, setEntries); }; - - const sortByUpdate = (elem, i) => { let newEntries = entries; switch (elem) { @@ -171,11 +168,11 @@ const AllEntries = (props) => { /> diff --git a/src/pages/Challanges/Challenges.js b/src/pages/Challanges/Challenges.js index 6310942..38f8b35 100644 --- a/src/pages/Challanges/Challenges.js +++ b/src/pages/Challanges/Challenges.js @@ -31,8 +31,9 @@ const Challenges = () => { }, []); React.useEffect(() => { - statusFilter(status, challenges, setChallenges); - }, [challenges, status]); + statusFilter(status, challengesFromAPI, setChallenges); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [status]); const challengesRequest = () => { getChallenges(setChallengesFromAPI); diff --git a/src/pages/Challanges/statusFilter.js b/src/pages/Challanges/statusFilter.js index 67cdec7..e7058da 100644 --- a/src/pages/Challanges/statusFilter.js +++ b/src/pages/Challanges/statusFilter.js @@ -1,5 +1,56 @@ +import { CHALLENGES_STATUS_FILTER } from '../../utils/globals'; + +const dateIsOlder = (newerDate, olderDate) => { + console.log(newerDate); + console.log(olderDate); + if (newerDate.year > olderDate.year) return true; + else if (newerDate.month > olderDate.month) return true; + else if (newerDate.day > olderDate.day) return true; + else return false; +}; + +const getDeadlineTime = (deadline) => { + if (deadline) { + return { + year: deadline.slice(0, 10).split('-')[0], + month: deadline.slice(0, 10).split('-')[1], + day: deadline.slice(0, 10).split('-')[2], + }; + } +}; + const statusFilter = (status, challenges, setChallenges) => { let result = challenges; + const date = new Date(); + const currentDate = { + year: date.getFullYear(), + month: date.getMonth(), + day: date.getDay(), + }; + switch (status) { + case CHALLENGES_STATUS_FILTER.CLOSED: + result = challenges.filter((challenge) => + dateIsOlder( + currentDate, + challenge.deadline ? getDeadlineTime(challenge.deadline) : false + ) + ); + setChallenges(result); + break; + case CHALLENGES_STATUS_FILTER.ACTIVE: + result = challenges.filter( + (challenge) => + !dateIsOlder( + currentDate, + challenge.deadline ? getDeadlineTime(challenge.deadline) : true + ) + ); + setChallenges(result); + break; + default: + setChallenges(challenges); + break; + } }; export default statusFilter;