diff --git a/src/features/courses/screens/CourseDirectoryScreen.tsx b/src/features/courses/screens/CourseDirectoryScreen.tsx index 5c86cfb2..62c086fc 100644 --- a/src/features/courses/screens/CourseDirectoryScreen.tsx +++ b/src/features/courses/screens/CourseDirectoryScreen.tsx @@ -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 { @@ -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 (