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