Skip to content

Commit 92330dc

Browse files
fix(exams): sort exams by date in the TeachingScreen.tsx, Ref #504
1 parent 3b32377 commit 92330dc

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/features/teaching/screens/TeachingScreen.tsx

+15-2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ import { Theme } from '@lib/ui/types/Theme';
2828
import { ExamStatusEnum } from '@polito/api-client';
2929
import { NativeStackScreenProps } from '@react-navigation/native-stack';
3030

31+
import { DateTime } from 'luxon';
32+
3133
import { BottomBarSpacer } from '../../../core/components/BottomBarSpacer';
3234
import { usePreferencesContext } from '../../../core/contexts/PreferencesContext';
3335
import { useNotifications } from '../../../core/hooks/useNotifications';
@@ -83,8 +85,19 @@ export const TeachingScreen = ({ navigation }: Props) => {
8385

8486
return (
8587
examsQuery.data
86-
.filter(e => !hiddenCourses.includes(e.uniqueShortcode))
87-
.sort(e => (e.status === ExamStatusEnum.Booked ? -1 : 1))
88+
.filter(
89+
e =>
90+
!hiddenCourses.includes(e.uniqueShortcode) &&
91+
e.examEndsAt!.valueOf() > DateTime.now().toJSDate().valueOf(),
92+
)
93+
.sort((a, b) => {
94+
const status =
95+
(a.status === ExamStatusEnum.Booked ? -1 : 0) +
96+
(b.status === ExamStatusEnum.Booked ? 1 : 0);
97+
return status !== 0
98+
? status
99+
: a.examStartsAt!.valueOf() - b.examStartsAt!.valueOf();
100+
})
88101
.slice(0, 4) ?? []
89102
);
90103
}, [coursePreferences, coursesQuery.data, examsQuery.data]);

0 commit comments

Comments
 (0)