From 5c0d1b79e0e5aa50b677bc4fb55a8a2a64a77adb Mon Sep 17 00:00:00 2001 From: Tryon Date: Tue, 1 Oct 2024 18:24:50 +0200 Subject: [PATCH] =?UTF-8?q?feat(ui):=20Ajouter=20une=20fonctionnalit=C3=A9?= =?UTF-8?q?=20pour=20afficher=20uniquement=20les=20cours=20de=20demain=20d?= =?UTF-8?q?ans=20l'=C3=A9l=C3=A9ment=20TimetableElement?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Home/Elements/TimetableElement.tsx | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/views/account/Home/Elements/TimetableElement.tsx b/src/views/account/Home/Elements/TimetableElement.tsx index d057aa8c3..43d539627 100644 --- a/src/views/account/Home/Elements/TimetableElement.tsx +++ b/src/views/account/Home/Elements/TimetableElement.tsx @@ -30,6 +30,17 @@ const TimetableElement = () => { ); }; + const isTomorrow = (timestamp: number) => { + const tomorrow = new Date(); + tomorrow.setDate(tomorrow.getDate() + 1); + const date = new Date(timestamp); + return ( + date.getDate() === tomorrow.getDate() && + date.getMonth() === tomorrow.getMonth() && + date.getFullYear() === tomorrow.getFullYear() + ); + }; + const fetchTimetable = async () => { if (!timetables[currentWeekNumber] && account.instance) { setLoading(true); @@ -51,6 +62,14 @@ const TimetableElement = () => { return todayCourses; } + const tomorrowCourses = weekCourses + .filter(c => isTomorrow(c.startTimestamp)) + .sort((a, b) => a.startTimestamp - b.startTimestamp); + + if (tomorrowCourses.length > 0) { + return tomorrowCourses.slice(0, 3); + } + return weekCourses .filter(c => c.startTimestamp > now) .sort((a, b) => a.startTimestamp - b.startTimestamp) @@ -110,14 +129,18 @@ const TimetableElement = () => { ); } - const label = isToday(nextCourses[0].startTimestamp) ? "Emploi du temps" : "Prochains cours"; + const label = isToday(nextCourses[0].startTimestamp) + ? "Emploi du temps" + : isTomorrow(nextCourses[0].startTimestamp) + ? "Cours de demain" + : "Prochains cours"; return ( <>