import { useEffect, useState } from 'react' import { View, Text, FlatList, TouchableOpacity, ActivityIndicator, RefreshControl, } from 'react-native' import { SafeAreaView } from 'react-native-safe-area-context' import { useLocalSearchParams, useRouter } from 'expo-router' import { ArrowLeft } from 'lucide-react-native' import { apiFetch } from '@/lib/api' import { ENDPOINTS } from '@/lib/config' interface Note { id: string title: string updatedAt: string } export default function NotebookScreen() { const { id } = useLocalSearchParams<{ id: string }>() const [notes, setNotes] = useState([]) const [notebookName, setNotebookName] = useState('') const [loading, setLoading] = useState(true) const [refreshing, setRefreshing] = useState(false) const router = useRouter() const load = async () => { try { const res = await apiFetch(ENDPOINTS.notes(id)) if (res.ok) { const data = await res.json() setNotes(data.notes ?? []) setNotebookName(data.notebookName ?? '') } } finally { setLoading(false) setRefreshing(false) } } useEffect(() => { load() }, [id]) return ( router.back()} className="p-1"> {notebookName || 'Carnet'} {loading ? ( ) : ( item.id} contentContainerClassName="px-5 pt-4 pb-8" refreshControl={ { setRefreshing(true); load() }} tintColor="#A47148" />} renderItem={({ item }) => ( router.push(`/note/${item.id}`)} className="bg-white border border-border rounded-2xl p-4 mb-2.5 active:opacity-70" > {item.title || 'Sans titre'} {new Date(item.updatedAt).toLocaleDateString('fr-FR', { day: 'numeric', month: 'short' })} )} ListEmptyComponent={Carnet vide.} /> )} ) }