diff --git a/mobile/app/index.tsx b/mobile/app/index.tsx index 8284e4e..724613c 100644 --- a/mobile/app/index.tsx +++ b/mobile/app/index.tsx @@ -1,11 +1,14 @@ import React from 'react'; -import { View, FlatList, StyleSheet, TouchableOpacity, Text } from 'react-native'; +import { View, FlatList, StyleSheet, TouchableOpacity, Text, Dimensions, Image } from 'react-native'; import { useNavigation } from '@react-navigation/native'; import { NativeStackNavigationProp } from '@react-navigation/native-stack'; import { useFiles } from '../hooks/useFiles'; -import { FileCard } from '../components/FileCard'; import { FileItem } from '../types'; +const NUM_COLUMNS = 3; +const SCREEN_WIDTH = Dimensions.get('window').width; +const ITEM_SIZE = (SCREEN_WIDTH - 16 * 2 - (NUM_COLUMNS - 1) * 6) / NUM_COLUMNS; + type RootStackParamList = { Home: undefined; Upload: undefined; @@ -15,21 +18,39 @@ type RootStackParamList = { type NavigationProp = NativeStackNavigationProp; +type GroupedFiles = Record; + +function groupByDate(files: FileItem[]): GroupedFiles { + const groups: GroupedFiles = {}; + for (const file of files) { + const d = new Date(file.createdAt); + const key = d.toLocaleDateString('fr-FR', { + weekday: 'long', year: 'numeric', month: 'long', day: 'numeric', + }); + if (!groups[key]) groups[key] = []; + groups[key].push(file); + } + return groups; +} + +function formatDateLabel(key: string): string { + const d = new Date(); + const today = d.toLocaleDateString('fr-FR', { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' }); + d.setDate(d.getDate() - 1); + const yesterday = d.toLocaleDateString('fr-FR', { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' }); + if (key === today) return "Aujourd'hui"; + if (key === yesterday) return 'Hier'; + return key.charAt(0).toUpperCase() + key.slice(1); +} + export function HomeScreen() { const navigation = useNavigation(); const { data, isLoading, error } = useFiles(); - const renderItem = ({ item }: { item: FileItem }) => ( - console.log('File pressed:', file.id)} - /> - ); - if (isLoading) { return ( - Chargement... + Chargement... ); } @@ -37,18 +58,43 @@ export function HomeScreen() { if (error) { return ( - Erreur de chargement + Erreur de chargement ); } + const files = data?.data ?? []; + const groups = groupByDate(files); + const groupKeys = Object.keys(groups); + return ( item.name} + data={groupKeys} + keyExtractor={(item) => item} contentContainerStyle={styles.list} + renderItem={({ item: dateKey }) => { + const groupFiles = groups[dateKey]; + return ( + + {formatDateLabel(dateKey)} + + {groupFiles.map((file) => ( + + {file.url ? ( + + ) : ( + + PDF + + )} + {file.name} + + ))} + + + ); + }} /> @@ -87,8 +133,55 @@ const styles = StyleSheet.create({ justifyContent: 'center', alignItems: 'center', }, + infoText: { + fontSize: 16, + color: '#666', + }, list: { padding: 16, + paddingBottom: 80, + }, + section: { + marginBottom: 24, + }, + sectionTitle: { + fontSize: 18, + fontWeight: '700', + marginBottom: 12, + color: '#333', + }, + grid: { + flexDirection: 'row', + flexWrap: 'wrap', + gap: 6, + }, + gridItem: { + width: ITEM_SIZE, + }, + thumb: { + width: ITEM_SIZE, + height: ITEM_SIZE, + borderRadius: 6, + backgroundColor: '#e0e0e0', + }, + placeholder: { + width: ITEM_SIZE, + height: ITEM_SIZE, + borderRadius: 6, + backgroundColor: '#e3f2fd', + justifyContent: 'center', + alignItems: 'center', + }, + placeholderText: { + fontSize: 12, + color: '#1976D2', + fontWeight: '600', + }, + fileName: { + fontSize: 11, + color: '#666', + marginTop: 4, + textAlign: 'center', }, bottomNav: { flexDirection: 'row',