Skip to content

Commit

Permalink
fix(courses): prioritize sorting by date, if they are the same sort b…
Browse files Browse the repository at this point in the history
…y name in increasing order (#536)
  • Loading branch information
FabrizioCostaMedich authored Nov 7, 2024
1 parent 61057f9 commit 906024f
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/features/courses/screens/CourseDirectoryScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import { CourseDirectory, CourseFileOverview } from '@polito/api-client';
import { useFocusEffect } from '@react-navigation/native';
import { NativeStackScreenProps } from '@react-navigation/native-stack';

import { DateTime } from 'luxon';

import { BottomBarSpacer } from '../../../core/components/BottomBarSpacer';
import { useSafeAreaSpacing } from '../../../core/hooks/useSafeAreaSpacing';
import {
Expand Down Expand Up @@ -59,6 +61,20 @@ export const CourseDirectoryScreen = ({ route, navigation }: Props) => {
});
}, [directoryName, navigation, t]);

directoryQuery.data?.sort((a, b) => {
if (a.type !== 'directory' && b.type !== 'directory') {
const dateA = DateTime.fromJSDate(a.createdAt).startOf('minute');
const dateB = DateTime.fromJSDate(b.createdAt).startOf('minute');

if (dateA.equals(dateB)) {
return a.name.toLowerCase().localeCompare(b.name.toLowerCase());
}

return dateA > dateB ? -1 : 1;
}
return 0;
});

return (
<CourseContext.Provider value={courseId}>
<CourseFilesCacheProvider>
Expand Down

0 comments on commit 906024f

Please sign in to comment.