test firebase
This commit is contained in:
@@ -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<Ressource[]>([]);
|
||||
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 <View style={styles.card}><Text>Item manquant</Text></View>;
|
||||
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 <View style={styles.card}><Text>Item manquant</Text></View>;
|
||||
return null;
|
||||
}
|
||||
return (
|
||||
<View style={styles.card}>
|
||||
<View style={styles.info}>
|
||||
<Image source={{ uri: item.Image }} style={styles.image} />
|
||||
@@ -38,13 +58,14 @@ export default function GestionnaireRessource() {
|
||||
<Text>{item.name}</Text>
|
||||
<Text>{item.type}</Text>
|
||||
</View>
|
||||
</View>);
|
||||
};
|
||||
</View>
|
||||
);
|
||||
};
|
||||
|
||||
return(
|
||||
return (
|
||||
<View style={styles.container}>
|
||||
<FlatList
|
||||
data={data}
|
||||
data={filteredData}
|
||||
renderItem={renderRessource}
|
||||
keyExtractor={(_, index) => index.toString()}
|
||||
contentContainerStyle={{ paddingBottom: 40 }}
|
||||
@@ -69,45 +90,48 @@ export default function GestionnaireRessource() {
|
||||
/>
|
||||
|
||||
<View style={styles.footer}>
|
||||
<Button title="Retour" onPress={() =>router.push('/(tabs)/bonjourFL')} />
|
||||
<Button
|
||||
title="Retour"
|
||||
onPress={() => router.push("/(tabs)/bonjourFL")}
|
||||
/>
|
||||
</View>
|
||||
</View>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
container: {
|
||||
flex: 1,
|
||||
backgroundColor: '#fff',
|
||||
backgroundColor: "#fff",
|
||||
},
|
||||
header: {
|
||||
marginTop: 60,
|
||||
marginBottom: 20,
|
||||
alignItems: 'center',
|
||||
alignItems: "center",
|
||||
paddingHorizontal: 20,
|
||||
},
|
||||
text: {
|
||||
fontSize: 22,
|
||||
fontWeight: 'bold',
|
||||
fontWeight: "bold",
|
||||
marginBottom: 10,
|
||||
},
|
||||
input: {
|
||||
width: '100%',
|
||||
width: "100%",
|
||||
borderWidth: 1,
|
||||
borderColor: '#ccc',
|
||||
borderColor: "#ccc",
|
||||
borderRadius: 10,
|
||||
padding: 10,
|
||||
fontSize: 16,
|
||||
},
|
||||
card: {
|
||||
flexDirection: 'row',
|
||||
flexDirection: "row",
|
||||
marginHorizontal: 20,
|
||||
marginBottom: 15,
|
||||
borderWidth: 1,
|
||||
borderColor: '#ddd',
|
||||
borderColor: "#ddd",
|
||||
borderRadius: 10,
|
||||
padding: 10,
|
||||
backgroundColor: '#fafafa',
|
||||
backgroundColor: "#fafafa",
|
||||
},
|
||||
image: {
|
||||
width: 80,
|
||||
@@ -117,10 +141,10 @@ const styles = StyleSheet.create({
|
||||
},
|
||||
info: {
|
||||
flex: 1,
|
||||
justifyContent: 'center',
|
||||
justifyContent: "center",
|
||||
},
|
||||
group: {
|
||||
fontWeight: 'bold',
|
||||
fontWeight: "bold",
|
||||
fontSize: 16,
|
||||
marginBottom: 5,
|
||||
},
|
||||
@@ -128,8 +152,8 @@ const styles = StyleSheet.create({
|
||||
padding: 20,
|
||||
},
|
||||
empty: {
|
||||
textAlign: 'center',
|
||||
textAlign: "center",
|
||||
marginTop: 30,
|
||||
color: '#888',
|
||||
color: "#888",
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
47
package-lock.json
generated
47
package-lock.json
generated
@@ -25,7 +25,7 @@
|
||||
"expo-symbols": "~1.0.7",
|
||||
"expo-system-ui": "~6.0.7",
|
||||
"expo-web-browser": "~15.0.8",
|
||||
"firebase": "^12.5.0",
|
||||
"firebase": "^12.6.0",
|
||||
"react": "19.1.0",
|
||||
"react-dom": "19.1.0",
|
||||
"react-native": "0.81.4",
|
||||
@@ -2265,10 +2265,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@firebase/ai": {
|
||||
"version": "2.5.0",
|
||||
"resolved": "https://registry.npmjs.org/@firebase/ai/-/ai-2.5.0.tgz",
|
||||
"integrity": "sha512-OXv/jZLRjV9jTejWA4KOvW8gM1hNsLvQSCPwKhi2CEfe0Nap3rM6z+Ial0PGqXga0WgzhpypEvJOFvaAUFX3kg==",
|
||||
"license": "Apache-2.0",
|
||||
"version": "2.6.0",
|
||||
"resolved": "https://registry.npmjs.org/@firebase/ai/-/ai-2.6.0.tgz",
|
||||
"integrity": "sha512-NGyE7NQDFznOv683Xk4+WoUv39iipa9lEfrwvvPz33ChzVbCCiB69FJQTK2BI/11pRtzYGbHo1/xMz7gxWWhJw==",
|
||||
"dependencies": {
|
||||
"@firebase/app-check-interop-types": "0.3.3",
|
||||
"@firebase/component": "0.7.0",
|
||||
@@ -2323,10 +2322,9 @@
|
||||
"license": "Apache-2.0"
|
||||
},
|
||||
"node_modules/@firebase/app": {
|
||||
"version": "0.14.5",
|
||||
"resolved": "https://registry.npmjs.org/@firebase/app/-/app-0.14.5.tgz",
|
||||
"integrity": "sha512-zyNY77xJOGwcuB+xCxF8z8lSiHvD4ox7BCsqLEHEvgqQoRjxFZ0fkROR6NV5QyXmCqRLodMM8J5d2EStOocWIw==",
|
||||
"license": "Apache-2.0",
|
||||
"version": "0.14.6",
|
||||
"resolved": "https://registry.npmjs.org/@firebase/app/-/app-0.14.6.tgz",
|
||||
"integrity": "sha512-4uyt8BOrBsSq6i4yiOV/gG6BnnrvTeyymlNcaN/dKvyU1GoolxAafvIvaNP1RCGPlNab3OuE4MKUQuv2lH+PLQ==",
|
||||
"dependencies": {
|
||||
"@firebase/component": "0.7.0",
|
||||
"@firebase/logger": "0.5.0",
|
||||
@@ -2389,12 +2387,11 @@
|
||||
"license": "Apache-2.0"
|
||||
},
|
||||
"node_modules/@firebase/app-compat": {
|
||||
"version": "0.5.5",
|
||||
"resolved": "https://registry.npmjs.org/@firebase/app-compat/-/app-compat-0.5.5.tgz",
|
||||
"integrity": "sha512-lVG/nRnXaot0rQSZazmTNqy83ti9O3+kdwoaE0d5wahRIWNoDirbIMcGVjDDgdmf4IE6FYreWOMh0L3DV1475w==",
|
||||
"license": "Apache-2.0",
|
||||
"version": "0.5.6",
|
||||
"resolved": "https://registry.npmjs.org/@firebase/app-compat/-/app-compat-0.5.6.tgz",
|
||||
"integrity": "sha512-YYGARbutghQY4zZUWMYia0ib0Y/rb52y72/N0z3vglRHL7ii/AaK9SA7S/dzScVOlCdnbHXz+sc5Dq+r8fwFAg==",
|
||||
"dependencies": {
|
||||
"@firebase/app": "0.14.5",
|
||||
"@firebase/app": "0.14.6",
|
||||
"@firebase/component": "0.7.0",
|
||||
"@firebase/logger": "0.5.0",
|
||||
"@firebase/util": "1.13.0",
|
||||
@@ -2483,10 +2480,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@firebase/data-connect": {
|
||||
"version": "0.3.11",
|
||||
"resolved": "https://registry.npmjs.org/@firebase/data-connect/-/data-connect-0.3.11.tgz",
|
||||
"integrity": "sha512-G258eLzAD6im9Bsw+Qm1Z+P4x0PGNQ45yeUuuqe5M9B1rn0RJvvsQCRHXgE52Z+n9+WX1OJd/crcuunvOGc7Vw==",
|
||||
"license": "Apache-2.0",
|
||||
"version": "0.3.12",
|
||||
"resolved": "https://registry.npmjs.org/@firebase/data-connect/-/data-connect-0.3.12.tgz",
|
||||
"integrity": "sha512-baPddcoNLj/+vYo+HSJidJUdr5W4OkhT109c5qhR8T1dJoZcyJpkv/dFpYlw/VJ3dV66vI8GHQFrmAZw/xUS4g==",
|
||||
"dependencies": {
|
||||
"@firebase/auth-interop-types": "0.2.4",
|
||||
"@firebase/component": "0.7.0",
|
||||
@@ -7907,22 +7903,21 @@
|
||||
}
|
||||
},
|
||||
"node_modules/firebase": {
|
||||
"version": "12.5.0",
|
||||
"resolved": "https://registry.npmjs.org/firebase/-/firebase-12.5.0.tgz",
|
||||
"integrity": "sha512-Ak8JcpH7FL6kiv0STwkv5+3CYEROO9iFWSx7OCZVvc4kIIABAIyAGs1mPGaHRxGUIApFZdMCXA7baq17uS6Mow==",
|
||||
"license": "Apache-2.0",
|
||||
"version": "12.6.0",
|
||||
"resolved": "https://registry.npmjs.org/firebase/-/firebase-12.6.0.tgz",
|
||||
"integrity": "sha512-8ZD1Gcv916Qp8/nsFH2+QMIrfX/76ti6cJwxQUENLXXnKlOX/IJZaU2Y3bdYf5r1mbownrQKfnWtrt+MVgdwLA==",
|
||||
"dependencies": {
|
||||
"@firebase/ai": "2.5.0",
|
||||
"@firebase/ai": "2.6.0",
|
||||
"@firebase/analytics": "0.10.19",
|
||||
"@firebase/analytics-compat": "0.2.25",
|
||||
"@firebase/app": "0.14.5",
|
||||
"@firebase/app": "0.14.6",
|
||||
"@firebase/app-check": "0.11.0",
|
||||
"@firebase/app-check-compat": "0.4.0",
|
||||
"@firebase/app-compat": "0.5.5",
|
||||
"@firebase/app-compat": "0.5.6",
|
||||
"@firebase/app-types": "0.9.3",
|
||||
"@firebase/auth": "1.11.1",
|
||||
"@firebase/auth-compat": "0.6.1",
|
||||
"@firebase/data-connect": "0.3.11",
|
||||
"@firebase/data-connect": "0.3.12",
|
||||
"@firebase/database": "1.1.0",
|
||||
"@firebase/database-compat": "2.1.0",
|
||||
"@firebase/firestore": "4.9.2",
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
"expo-symbols": "~1.0.7",
|
||||
"expo-system-ui": "~6.0.7",
|
||||
"expo-web-browser": "~15.0.8",
|
||||
"firebase": "^12.5.0",
|
||||
"firebase": "^12.6.0",
|
||||
"react": "19.1.0",
|
||||
"react-dom": "19.1.0",
|
||||
"react-native": "0.81.4",
|
||||
|
||||
21
services/ressourcesService.ts
Normal file
21
services/ressourcesService.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { collection, getDocs } from "firebase/firestore";
|
||||
import { db } from "../firebase_config";
|
||||
|
||||
export type Ressource = {
|
||||
id: number;
|
||||
name: string;
|
||||
type: string;
|
||||
Image: string;
|
||||
};
|
||||
|
||||
export async function getRessources(): Promise<Ressource[]> {
|
||||
try {
|
||||
const ressourcesCol = collection(db, "ressources");
|
||||
const snapshot = await getDocs(ressourcesCol);
|
||||
const list = snapshot.docs.map((doc) => doc.data() as Ressource);
|
||||
return list;
|
||||
} catch (err) {
|
||||
console.log("Firestore Error:", err);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user