diff --git a/app/(tabs)/gestionnaire_ressource.tsx b/app/(tabs)/gestionnaire_ressource.tsx index 4023989..949ede5 100644 --- a/app/(tabs)/gestionnaire_ressource.tsx +++ b/app/(tabs)/gestionnaire_ressource.tsx @@ -1,36 +1,56 @@ -import { useRouter , useLocalSearchParams} from "expo-router"; +import { useRouter, useLocalSearchParams } from "expo-router"; import { navigate } from "expo-router/build/global-state/routing"; -import React, {useState} from 'react'; -import { Button,FlatList,Image, Text, TextInput,View, StyleSheet } from 'react-native'; +import React, { useEffect, useState } from "react"; +import { + Button, + FlatList, + Image, + Text, + TextInput, + View, + StyleSheet, +} from "react-native"; +import { getRessources, Ressource } from "../../services/ressourcesService"; export default function GestionnaireRessource() { const { nom, prenom } = useLocalSearchParams(); // Recup data ecran precedent - const [search, setSearch] = useState(''); + const [search, setSearch] = useState(""); + const [ressource, setRessources] = useState([]); + const [loading, setLoading] = useState(true); const router = useRouter(); - type Ressource ={ - id: number; - name: string; - type: string; - Image: string; - } - - const data: Ressource[] = [ - { id: 1, name: 'Marteau', type: 'Outil', Image: '' }, - { id: 2, name: 'Scie', type: 'Outil' , Image: ''}, - { id: 3, name: 'Pelle', type: 'Outil' , Image: '' }, - { id: 4, name: 'Grue', type: 'Machine',Image: 'https://media.discordapp.net/attachments/1425108443571945644/1427207643180826757/raw.png?ex=68ee0632&is=68ecb4b2&hm=1efc51065c6abfb1af75b8382f9924c2eb177c7d7672f7ed9837e96ef3076d16&=&format=webp&quality=lossless&width=421&height=632'}, - { id: 5, name: 'Bulldozer', type: 'Machine', Image: ''}, - ]; - - - const renderRessource = ({ item, index }: { item?: Ressource; index: number }) => { - if (!item) { - // optionnel : afficher un placeholder pour debug - // return Item manquant; - return null; + useEffect(() => { + async function loadData() { + try { + const data = await getRessources(); + setRessources(data); + } catch (error) { + console.error("Erreur lors du chargement des ressources :", error); + } finally { + setLoading(false); } - return( + } + + loadData(); + }, []); + + const filteredData = ressource.filter((r) => + r.name.toLowerCase().includes(search.toLowerCase()) + ); + + const renderRessource = ({ + item, + index, + }: { + item?: Ressource; + index: number; + }) => { + if (!item) { + // optionnel : afficher un placeholder pour debug + // return Item manquant; + return null; + } + return ( @@ -38,13 +58,14 @@ export default function GestionnaireRessource() { {item.name} {item.type} - ); - }; + + ); + }; - return( + return ( index.toString()} contentContainerStyle={{ paddingBottom: 40 }} @@ -69,45 +90,48 @@ export default function GestionnaireRessource() { /> -