Auto recup des chantiers dans Firebase et affichage

This commit is contained in:
Alexis Leboeuf
2025-12-09 15:52:18 +01:00
parent 84df00230e
commit 2963c722b8

View File

@@ -1,10 +1,15 @@
// MapScreen.tsx // MapScreen.tsx
import { ThemedMapView } from '@/components/themed-mapview'; import { ThemedMapView } from '@/components/themed-mapview';
import React from 'react'; import React, { useEffect, useState } from 'react';
import { StyleSheet, View, Dimensions } from 'react-native'; import { StyleSheet, View, Dimensions, Image, Text } from 'react-native';
import MapView, { Marker, PROVIDER_DEFAULT } from 'react-native-maps'; import MapView, { Marker, Callout, CalloutSubview, PROVIDER_DEFAULT } from 'react-native-maps';
import { db } from '../../firebase_config';
import { Chantier } from '@/class/class';
import { getChantiers } from '@/services/ressourcesService';
const MapScreen = () => {
const MapScreen: React.FC = () => {
const region = { const region = {
latitude: 48.8566, latitude: 48.8566,
longitude: 2.3522, longitude: 2.3522,
@@ -12,6 +17,24 @@ const MapScreen: React.FC = () => {
longitudeDelta: 0.05, longitudeDelta: 0.05,
}; };
const [chantiers, setMarkers] = useState<Chantier[]>([]);
const [loading, setLoading] = useState(true);
useEffect(() => {
async function loadData() {
try {
const data = await getChantiers();
setMarkers(data);
} catch (error) {
console.error("Erreur lors du chargement :", error);
} finally {
setLoading(false);
}
}
loadData();
}, []);
return ( return (
<View style={styles.container}> <View style={styles.container}>
<ThemedMapView <ThemedMapView
@@ -19,11 +42,12 @@ const MapScreen: React.FC = () => {
style={styles.map} style={styles.map}
region={region} region={region}
> >
{chantiers.map(chantier => (
<Marker <Marker
coordinate={{ latitude: 48.8566, longitude: 2.3522 }} key={chantier.id}
title="Paris" coordinate={{ latitude: chantier.latitude, longitude: chantier.longitude }}
description="Capitale de la France"
/> />
))}
</ThemedMapView> </ThemedMapView>
</View> </View>
); );