Skip to content

Commit

Permalink
Merge pull request #245 from PapillonApp/elements/timetable/fix
Browse files Browse the repository at this point in the history
feat(ui): Ajouter une fonctionnalité pour afficher uniquement les cours de demain dans l'élément TimetableElement
  • Loading branch information
tryon-dev authored Oct 1, 2024
2 parents d56980e + 5c0d1b7 commit d817399
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions src/views/account/Home/Elements/TimetableElement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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)
Expand Down Expand Up @@ -110,14 +129,18 @@ const TimetableElement = () => {
<MissingItem
emoji="📚"
title="Aucun cours à venir"
description="Il n'y a pas de cours à venir pour aujourd'hui."
description="Il n'y a pas de cours à venir pour les prochains jours."
/>
</NativeItem>
</NativeList>
);
}

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

0 comments on commit d817399

Please sign in to comment.