Skip to content

Commit

Permalink
fix(exams): sort exams by date in the TeachingScreen.tsx, Ref #504 (#505
Browse files Browse the repository at this point in the history
)
  • Loading branch information
FabrizioCostaMedich authored Jul 8, 2024
1 parent 3b32377 commit 7c84dd0
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/features/teaching/screens/TeachingScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import { Theme } from '@lib/ui/types/Theme';
import { ExamStatusEnum } from '@polito/api-client';
import { NativeStackScreenProps } from '@react-navigation/native-stack';

import { DateTime } from 'luxon';

import { BottomBarSpacer } from '../../../core/components/BottomBarSpacer';
import { usePreferencesContext } from '../../../core/contexts/PreferencesContext';
import { useNotifications } from '../../../core/hooks/useNotifications';
Expand Down Expand Up @@ -83,8 +85,19 @@ export const TeachingScreen = ({ navigation }: Props) => {

return (
examsQuery.data
.filter(e => !hiddenCourses.includes(e.uniqueShortcode))
.sort(e => (e.status === ExamStatusEnum.Booked ? -1 : 1))
.filter(
e =>
!hiddenCourses.includes(e.uniqueShortcode) &&
e.examEndsAt!.valueOf() > DateTime.now().toJSDate().valueOf(),
)
.sort((a, b) => {
const status =
(a.status === ExamStatusEnum.Booked ? -1 : 0) +
(b.status === ExamStatusEnum.Booked ? 1 : 0);
return status !== 0
? status
: a.examStartsAt!.valueOf() - b.examStartsAt!.valueOf();
})
.slice(0, 4) ?? []
);
}, [coursePreferences, coursesQuery.data, examsQuery.data]);
Expand Down

0 comments on commit 7c84dd0

Please sign in to comment.