import { useState, useCallback } from 'react'; import { View, Text, StyleSheet, FlatList, TouchableOpacity, Alert, RefreshControl } from 'react-native'; import { useRouter } from 'expo-router'; import { Ionicons } from '@expo/vector-icons'; import { useSaisies, useDeleteSaisie } from '@/hooks/useTracker'; import { Colors } from '@/lib/colors'; import type { SaisieTracker } from '@/types'; export default function JournalScreen() { const router = useRouter(); const { data: saisies, isLoading, refetch } = useSaisies(); const deleteSaisie = useDeleteSaisie(); const [refreshing, setRefreshing] = useState(false); const onRefresh = useCallback(async () => { setRefreshing(true); await refetch(); setRefreshing(false); }, [refetch]); const handleDelete = (id: number) => { Alert.alert('Supprimer', 'Supprimer cette saisie ?', [ { text: 'Annuler', style: 'cancel' }, { text: 'Supprimer', style: 'destructive', onPress: async () => { try { await deleteSaisie.mutateAsync(id); } catch { Alert.alert('Erreur', 'Impossible de supprimer'); } }, }, ]); }; const renderItem = ({ item }: { item: SaisieTracker }) => ( {item.emotion?.icone || '🔵'} {item.emotion?.nom} Intensite: {item.intensite}/10 {item.note && {item.note}} {new Date(item.date_saisie).toLocaleDateString('fr-FR', { weekday: 'long', day: 'numeric', month: 'long' })} router.push({ pathname: '/(tabs)/journal/edit', params: { id: String(item.id) } })}> handleDelete(item.id)}> ); return ( String(item.id)} renderItem={renderItem} contentContainerStyle={styles.listContent} refreshControl={} ListEmptyComponent={ Aucune saisie Commencez par enregistrer votre premiere emotion } /> router.push('/(tabs)/journal/new')}> ); } const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: Colors.white }, listContent: { padding: 16, paddingBottom: 80 }, saisieCard: { flexDirection: 'row', alignItems: 'flex-start', gap: 12, padding: 16, backgroundColor: Colors.gray[50], borderRadius: 16, marginBottom: 10, borderWidth: 1, borderColor: Colors.gray[100], }, emotionIcon: { width: 48, height: 48, borderRadius: 14, justifyContent: 'center', alignItems: 'center' }, emotionEmoji: { fontSize: 24 }, saisieContent: { flex: 1 }, saisieHeader: { flexDirection: 'row', alignItems: 'center', gap: 8, marginBottom: 6 }, badge: { paddingHorizontal: 10, paddingVertical: 3, borderRadius: 8 }, badgeText: { fontSize: 13, fontWeight: '600' }, intensityText: { fontSize: 12, color: Colors.gray[400] }, intensityBar: { height: 4, backgroundColor: Colors.gray[200], borderRadius: 2, marginBottom: 6 }, intensityFill: { height: 4, borderRadius: 2 }, note: { fontSize: 13, color: Colors.gray[600], marginBottom: 4 }, date: { fontSize: 12, color: Colors.gray[400] }, actions: { gap: 4 }, actionBtn: { padding: 6, borderRadius: 8 }, empty: { alignItems: 'center', paddingTop: 80 }, emptyTitle: { fontSize: 18, fontWeight: '600', color: Colors.gray[400], marginTop: 12 }, emptyText: { fontSize: 14, color: Colors.gray[400], marginTop: 4 }, fab: { position: 'absolute', right: 20, bottom: 20, width: 56, height: 56, borderRadius: 28, backgroundColor: Colors.primary, justifyContent: 'center', alignItems: 'center', shadowColor: '#000', shadowOffset: { width: 0, height: 4 }, shadowOpacity: 0.2, shadowRadius: 8, elevation: 6, }, });