From 289480fccc7455b5ee716930c069d030b150a0da Mon Sep 17 00:00:00 2001 From: Louis Date: Sat, 19 Oct 2024 22:04:46 +0200 Subject: [PATCH] Refactor HomeworksElement to handle empty hwFinalList and hwFinalList2 --- src/views/account/Home/Elements/HomeworksElement.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/views/account/Home/Elements/HomeworksElement.tsx b/src/views/account/Home/Elements/HomeworksElement.tsx index f42b2cc8c..1af0b9e85 100644 --- a/src/views/account/Home/Elements/HomeworksElement.tsx +++ b/src/views/account/Home/Elements/HomeworksElement.tsx @@ -48,8 +48,8 @@ const HomeworksElement = ({ navigation }) => { const startTime = Date.now() / 1000; // Convertir en millisecondes const endTime = startTime + 7 * 24 * 60 * 60 * 1000; // Ajouter 7 jours en millisecondes - const hwFinalList = homeworks[(new Date().getDay() === 6 || new Date().getDay() === 0) ? dateToEpochWeekNumber(actualDay) + 1 : dateToEpochWeekNumber(actualDay)]?.filter(hw => hw.due / 1000 >= startTime && hw.due / 1000 <= endTime); - const hwFinalList2 = homeworks[(new Date().getDay() === 5 || new Date().getDay() === 6 || new Date().getDay() === 0) ? dateToEpochWeekNumber(actualDay) + 2 : dateToEpochWeekNumber(actualDay) + 1]?.filter(hw => hw.due / 1000 >= startTime && hw.due / 1000 <= endTime); + const hwFinalList = homeworks[(new Date().getDay() === 6 || new Date().getDay() === 0) ? dateToEpochWeekNumber(actualDay) + 1 : dateToEpochWeekNumber(actualDay)]?.filter(hw => hw.due / 1000 >= startTime && hw.due / 1000 <= endTime) || []; + const hwFinalList2 = homeworks[(new Date().getDay() === 5 || new Date().getDay() === 6 || new Date().getDay() === 0) ? dateToEpochWeekNumber(actualDay) + 2 : dateToEpochWeekNumber(actualDay) + 1]?.filter(hw => hw.due / 1000 >= startTime && hw.due / 1000 <= endTime) || []; if(hwFinalList.length === 0) { return null; @@ -75,13 +75,13 @@ const HomeworksElement = ({ navigation }) => { }} /> ))} - {new Date().getDay() >= 2 && hwFinalList2 && hwFinalList2.length > 0 && hwFinalList2.map((hw, index) => ( + {new Date().getDay() >= 2 && hwFinalList2.length > 0 && hwFinalList2.map((hw, index) => ( { handleDonePress(hw); }}