Merging
This commit is contained in:
@@ -23,67 +23,61 @@ export default function TabLayout() {
|
|||||||
const colorScheme = useColorScheme();
|
const colorScheme = useColorScheme();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<UserProvider>
|
<Tabs.Navigator
|
||||||
<ChantierProvider>
|
initialRouteName='explore'
|
||||||
<RessourcesProvider>
|
screenOptions={{
|
||||||
<Tabs.Navigator
|
tabBarActiveTintColor: Colors[colorScheme ?? 'light'].tint,
|
||||||
initialRouteName='explore'
|
headerShown: false,
|
||||||
screenOptions={{
|
tabBarButton: HapticTab,
|
||||||
tabBarActiveTintColor: Colors[colorScheme ?? 'light'].tint,
|
}}>
|
||||||
headerShown: false,
|
<Tabs.Screen
|
||||||
tabBarButton: HapticTab,
|
name="home"
|
||||||
}}>
|
component={Home}
|
||||||
<Tabs.Screen
|
options={{
|
||||||
name="home"
|
title: 'Home',
|
||||||
component={Home}
|
tabBarIcon: ({ color }) => (
|
||||||
options={{
|
<IconSymbol size={28} name="house.fill" color={color} />
|
||||||
title: 'Home',
|
),
|
||||||
tabBarIcon: ({ color }) => (
|
}}
|
||||||
<IconSymbol size={28} name="house.fill" color={color} />
|
/>
|
||||||
),
|
<Tabs.Screen
|
||||||
}}
|
name="gestionnaire_ressource"
|
||||||
/>
|
component={ListMateriel}
|
||||||
<Tabs.Screen
|
options={{
|
||||||
name="gestionnaire_ressource"
|
title: 'Ressources',
|
||||||
component={ListMateriel}
|
tabBarIcon: ({ color }) => (
|
||||||
options={{
|
<IconSymbol size={28} name="backpack.fill" color={color} />
|
||||||
title: 'Ressources',
|
),
|
||||||
tabBarIcon: ({ color }) => (
|
}}
|
||||||
<IconSymbol size={28} name="backpack.fill" color={color} />
|
/>
|
||||||
),
|
<Tabs.Screen
|
||||||
}}
|
name="GestionOuvrier"
|
||||||
/>
|
component={GestionOuvrier}
|
||||||
<Tabs.Screen
|
options={{
|
||||||
name="GestionOuvrier"
|
title: 'Bonjour',
|
||||||
component={GestionOuvrier}
|
tabBarIcon: ({ color }) => <IconSymbol size={28} name="person.fill" color={color} />,
|
||||||
options={{
|
}}
|
||||||
title: 'Bonjour',
|
/>
|
||||||
tabBarIcon: ({ color }) => <IconSymbol size={28} name="person.fill" color={color} />,
|
<Tabs.Screen
|
||||||
}}
|
name="explore"
|
||||||
/>
|
component={MapScreen}
|
||||||
<Tabs.Screen
|
options={{
|
||||||
name="explore"
|
title: 'MapScreen',
|
||||||
component={MapScreen}
|
tabBarIcon: ({ color }) => <IconSymbol size={28} name="paperplane.fill" color={color} />,
|
||||||
options={{
|
}}
|
||||||
title: 'MapScreen',
|
>
|
||||||
tabBarIcon: ({ color }) => <IconSymbol size={28} name="paperplane.fill" color={color} />,
|
</Tabs.Screen>
|
||||||
}}
|
<Tabs.Screen
|
||||||
>
|
name="addChantier"
|
||||||
</Tabs.Screen>
|
component={AddChantier}
|
||||||
<Tabs.Screen
|
options={{
|
||||||
name="addChantier"
|
title: 'Ajouter',
|
||||||
component={AddChantier}
|
tabBarIcon: ({ color }) => (
|
||||||
options={{
|
<AntDesign name="plus" size={24} color={color} />
|
||||||
title: 'Ajouter',
|
),
|
||||||
tabBarIcon: ({ color }) => (
|
}}
|
||||||
<AntDesign name="plus" size={24} color={color} />
|
/>
|
||||||
),
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
|
|
||||||
</Tabs.Navigator>
|
</Tabs.Navigator>
|
||||||
</RessourcesProvider>
|
|
||||||
</ChantierProvider>
|
|
||||||
</UserProvider>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -103,8 +103,9 @@ export default function AddChantier() {
|
|||||||
<ThemedTextInput lvl = {1} style = {styles.input} placeholder='Adresse du chantier' value = {adresse} onChangeText={setAdresse} />
|
<ThemedTextInput lvl = {1} style = {styles.input} placeholder='Adresse du chantier' value = {adresse} onChangeText={setAdresse} />
|
||||||
<ThemedTextInput lvl = {1} style = {styles.input} placeholder='durée estimée (en jours)' value = {duree} onChangeText={setDuree} />
|
<ThemedTextInput lvl = {1} style = {styles.input} placeholder='durée estimée (en jours)' value = {duree} onChangeText={setDuree} />
|
||||||
<ThemedTextInput lvl = {1} style = {styles.input} placeholder='chef de chantier' value= {chefChantier} onChangeText={setChefChantier}/>
|
<ThemedTextInput lvl = {1} style = {styles.input} placeholder='chef de chantier' value= {chefChantier} onChangeText={setChefChantier}/>
|
||||||
<ThemedText style={{ fontWeight: "bold", marginTop: 15 }}>Équipe</ThemedText>
|
<ThemedText style = {styles.text}>Ajouter un équipier</ThemedText>
|
||||||
<Text style={{ fontWeight: "bold", marginTop: 15 }}>Ressources</Text>
|
|
||||||
|
<ThemedText style = {styles.text}>Ajouter une ressources</ThemedText>
|
||||||
<ThemedButton
|
<ThemedButton
|
||||||
lvl={1}
|
lvl={1}
|
||||||
shadow={true}
|
shadow={true}
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ export default function Home() {
|
|||||||
return(
|
return(
|
||||||
<ThemedView lvl={3} style={styles.back}>
|
<ThemedView lvl={3} style={styles.back}>
|
||||||
<View style={styles.container}>
|
<View style={styles.container}>
|
||||||
<ChantierSummary style={styles.summary} data={{ chantier }} />
|
|
||||||
<View style={{width:"100%", position: 'absolute'}}>
|
<View style={{width:"100%", position: 'absolute'}}>
|
||||||
<SelectChantier></SelectChantier>
|
<SelectChantier></SelectChantier>
|
||||||
</View>
|
</View>
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import { auth, db } from "../firebase_config";
|
|||||||
import { Platform, UIManager } from 'react-native';
|
import { Platform, UIManager } from 'react-native';
|
||||||
import { ChantierProvider } from "./ContextChantier";
|
import { ChantierProvider } from "./ContextChantier";
|
||||||
import { UserProvider } from "./ContextUser";
|
import { UserProvider } from "./ContextUser";
|
||||||
|
import { RessourcesProvider } from "./ContextRessource";
|
||||||
|
|
||||||
|
|
||||||
export const unstable_settings = {
|
export const unstable_settings = {
|
||||||
@@ -57,18 +58,20 @@ export default function RootLayout() {
|
|||||||
return (
|
return (
|
||||||
<UserProvider>
|
<UserProvider>
|
||||||
<ChantierProvider>
|
<ChantierProvider>
|
||||||
<ThemeProvider value={colorScheme === "dark" ? DarkTheme : DefaultTheme}>
|
<RessourcesProvider>
|
||||||
<Stack>
|
<ThemeProvider value={colorScheme === "dark" ? DarkTheme : DefaultTheme}>
|
||||||
<Stack.Screen name="(tabs)" options={{ headerShown: false }} />
|
<Stack>
|
||||||
<Stack.Screen name="selectChantier" options={{ headerShown: false }}/>
|
<Stack.Screen name="(tabs)" options={{ headerShown: false }} />
|
||||||
<Stack.Screen
|
<Stack.Screen name="selectChantier" options={{ headerShown: false }}/>
|
||||||
name="modal"
|
<Stack.Screen
|
||||||
options={{ presentation: "modal", title: "Modal" }}
|
name="modal"
|
||||||
/>
|
options={{ presentation: "modal", title: "Modal" }}
|
||||||
<Stack.Screen name="login" options={{ headerShown: false }} />
|
/>
|
||||||
</Stack>
|
<Stack.Screen name="login" options={{ headerShown: false }} />
|
||||||
<StatusBar style="auto" />
|
</Stack>
|
||||||
</ThemeProvider>
|
<StatusBar style="auto" />
|
||||||
|
</ThemeProvider>
|
||||||
|
</RessourcesProvider>
|
||||||
</ChantierProvider>
|
</ChantierProvider>
|
||||||
</UserProvider>
|
</UserProvider>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
import { useChantier } from "@/app/ContextChantier";
|
import { useChantier } from "@/app/ContextChantier";
|
||||||
import { Chantier } from "@/class/class";
|
import { Chantier } from "@/class/class";
|
||||||
import { getChantiers } from "@/services/ressourcesService";
|
import { getChantiers } from "@/services/ressourcesService";
|
||||||
|
import { useRouter } from "expo-router";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import {
|
import {
|
||||||
|
ActivityIndicator,
|
||||||
Dimensions,
|
Dimensions,
|
||||||
Image,
|
Image,
|
||||||
Pressable,
|
Pressable,
|
||||||
@@ -13,11 +15,10 @@ import {
|
|||||||
import Animated, {
|
import Animated, {
|
||||||
LinearTransition
|
LinearTransition
|
||||||
} from "react-native-reanimated";
|
} from "react-native-reanimated";
|
||||||
import { ThemedButton } from "./theme/themed-button";
|
import { ThemedButton } from "@/components/theme/themed-button";
|
||||||
import { ThemedText } from "./theme/themed-text";
|
import { ThemedText } from "@/components/theme/themed-text";
|
||||||
import { ThemedTextInput } from "./theme/themed-textinput";
|
import { ThemedTextInput } from "@/components/theme/themed-textinput";
|
||||||
import { ThemedView } from "./theme/themed-view";
|
import { ThemedView } from "@/components/theme/themed-view";
|
||||||
import { router } from "expo-router";
|
|
||||||
|
|
||||||
const screenHeight = Dimensions.get("window").height;
|
const screenHeight = Dimensions.get("window").height;
|
||||||
const { width, height } = Dimensions.get("window");
|
const { width, height } = Dimensions.get("window");
|
||||||
@@ -30,18 +31,14 @@ const { width, height } = Dimensions.get("window");
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export default function SelectChantier(props: {
|
export default function SelectChantier() {
|
||||||
data?: any[];
|
|
||||||
multiple?: boolean;
|
|
||||||
selected?: string[] | string | null;
|
|
||||||
onChange?: (val: any) => void;
|
|
||||||
placeholder?: string;
|
|
||||||
}) {
|
|
||||||
const { data: propData, multiple = false, selected, onChange, placeholder } = props || {};
|
|
||||||
const { chantier, setChantier } = useChantier();
|
const { chantier, setChantier } = useChantier();
|
||||||
const [search, setSearch] = useState("");
|
const [search, setSearch] = useState("");
|
||||||
const [isOpen, setIsOpen] = useState(false);
|
const [isOpen, setIsOpen] = useState(false);
|
||||||
const [chantiers, setChantiers] = useState<any[]>([]);
|
const [isLoaded, setIsLoaded] = useState(false);
|
||||||
|
const [chantiers, setChantiers] = useState<Chantier[]>([]);
|
||||||
|
const router = useRouter();
|
||||||
|
|
||||||
|
|
||||||
const AnimatedThemedView = Animated.createAnimatedComponent(ThemedView);
|
const AnimatedThemedView = Animated.createAnimatedComponent(ThemedView);
|
||||||
const AnimatedThemedText = Animated.createAnimatedComponent(ThemedText);
|
const AnimatedThemedText = Animated.createAnimatedComponent(ThemedText);
|
||||||
@@ -50,29 +47,21 @@ export default function SelectChantier(props: {
|
|||||||
Animated.createAnimatedComponent(ThemedTextInput);
|
Animated.createAnimatedComponent(ThemedTextInput);
|
||||||
|
|
||||||
async function onPressOpen(){
|
async function onPressOpen(){
|
||||||
|
setIsLoaded(false);
|
||||||
setIsOpen(!isOpen);
|
setIsOpen(!isOpen);
|
||||||
if(!isOpen){
|
if(!isOpen){
|
||||||
if (propData && propData.length) {
|
const updatedChantiers = await getChantiers();
|
||||||
setChantiers(propData as any[]);
|
setIsLoaded(true);
|
||||||
} else {
|
setChantiers(updatedChantiers)
|
||||||
const updatedChantiers = await getChantiers();
|
|
||||||
setChantiers(updatedChantiers);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function onPressAddChantier(){
|
function onPressAddChantier(){
|
||||||
router.push('/(tabs)/addChantier')
|
router.push("/(tabs)/addChantier")
|
||||||
setIsOpen(false)
|
setIsOpen(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// If parent provided data, use it. Otherwise fetch chantiers.
|
|
||||||
if (propData && propData.length) {
|
|
||||||
setChantiers(propData as any[]);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function loadChantiers() {
|
async function loadChantiers() {
|
||||||
const list = await getChantiers();
|
const list = await getChantiers();
|
||||||
setChantiers(list);
|
setChantiers(list);
|
||||||
@@ -81,56 +70,22 @@ export default function SelectChantier(props: {
|
|||||||
loadChantiers();
|
loadChantiers();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
function getId(item: any) {
|
function selectChantier(chantier: Chantier): void {
|
||||||
return (item && (item.id ?? item._id ?? item.uid ?? item.key)) ?? String(item);
|
setChantier(chantier);
|
||||||
}
|
|
||||||
|
|
||||||
function getLabel(item: any) {
|
|
||||||
if (!item) return String(item);
|
|
||||||
if (item.adresse) return item.adresse;
|
|
||||||
if (item.nom) return item.nom;
|
|
||||||
if (item.name && item.last_name) return `${item.last_name} ${item.name}`;
|
|
||||||
if (item.name) return item.name;
|
|
||||||
if (item.label) return item.label;
|
|
||||||
if (typeof item === 'string') return item;
|
|
||||||
return JSON.stringify(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
function selectChantier(item: any): void {
|
|
||||||
const id = String(getId(item));
|
|
||||||
if (multiple) {
|
|
||||||
// for multiple selection toggle id in selected array
|
|
||||||
const current = Array.isArray(selected) ? [...selected] : [];
|
|
||||||
const idx = current.indexOf(id);
|
|
||||||
if (idx >= 0) current.splice(idx, 1);
|
|
||||||
else current.push(id);
|
|
||||||
onChange?.(current);
|
|
||||||
// keep menu open for multiple selection
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// single selection
|
|
||||||
if (onChange) {
|
|
||||||
onChange(id);
|
|
||||||
} else {
|
|
||||||
// fallback behavior for old usage: if selecting a Chantier, update context
|
|
||||||
setChantier(item as Chantier);
|
|
||||||
}
|
|
||||||
setIsOpen(false);
|
setIsOpen(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
const renderChantier = (item: any, index: number) => {
|
const renderChantier = (chantier: Chantier, index: number) => {
|
||||||
const label = getLabel(item);
|
|
||||||
const id = String(getId(item));
|
|
||||||
const isSelected = Array.isArray(selected) ? selected.includes(id) : selected === id;
|
|
||||||
return (
|
return (
|
||||||
<Pressable key={index} onPress={() => selectChantier(item)}>
|
<Pressable key={index} onPress={() => selectChantier(chantier)}>
|
||||||
<ThemedView lvl={4} style={[styles.chantier, isSelected ? { borderWidth: 1 } : {}]}>
|
<ThemedView lvl={4} style={styles.chantier}>
|
||||||
<View>
|
<View>
|
||||||
<Image source={{ uri: "https://cdn.discordapp.com/attachments/1425108443571945644/1427207643180826757/raw.png?ex=69392bb2&is=6937da32&hm=dcc09e76d3dca89d2418947b46efbd38673b9dc559027724b2e51d493b173bc9&" }} style={styles.image} />
|
<Image source={{ uri:"https://cdn.discordapp.com/attachments/1425108443571945644/1427207643180826757/raw.png?ex=69392bb2&is=6937da32&hm=dcc09e76d3dca89d2418947b46efbd38673b9dc559027724b2e51d493b173bc9&" /*chantier.urlImg*/ }} style={styles.image} />
|
||||||
</View>
|
</View>
|
||||||
<View>
|
<View>
|
||||||
<ThemedText>{label}</ThemedText>
|
<ThemedText>Adresse: {chantier.adresse}</ThemedText>
|
||||||
|
<ThemedText>Chef de chantier: {chantier.chef.last_name}{" "}{chantier.chef.name}</ThemedText>
|
||||||
|
<ThemedText>État: {chantier.etat}</ThemedText>
|
||||||
</View>
|
</View>
|
||||||
</ThemedView>
|
</ThemedView>
|
||||||
</Pressable>
|
</Pressable>
|
||||||
@@ -143,19 +98,7 @@ export default function SelectChantier(props: {
|
|||||||
<AnimatedThemedView layout={LinearTransition.duration(200)} lvl={2} shadow={true} style={styles.window}>
|
<AnimatedThemedView layout={LinearTransition.duration(200)} lvl={2} shadow={true} style={styles.window}>
|
||||||
<AnimatedThemedButton style={isOpen ? styles.buttonOpen : styles.buttonClose} lvl={isOpen ? 1 : 1} onPress={() => onPressOpen()}>
|
<AnimatedThemedButton style={isOpen ? styles.buttonOpen : styles.buttonClose} lvl={isOpen ? 1 : 1} onPress={() => onPressOpen()}>
|
||||||
<ThemedText style={styles.buttonText}>
|
<ThemedText style={styles.buttonText}>
|
||||||
{isOpen
|
{isOpen ? "Fermer" : (chantier!=null ? chantier.adresse : "Chantier")}
|
||||||
? "Fermer"
|
|
||||||
: (multiple
|
|
||||||
? (Array.isArray(selected) && selected.length ? `${selected.length} sélectionnés` : (placeholder ?? "Sélectionner"))
|
|
||||||
: (selected ? (() => {
|
|
||||||
// show label of selected single item if provided in propData
|
|
||||||
if (selected && propData) {
|
|
||||||
const found = propData.find((it: any) => String(getId(it)) === String(selected));
|
|
||||||
return found ? getLabel(found) : (chantier ? (chantier.adresse ?? getLabel(chantier)) : (placeholder ?? "Chantier"));
|
|
||||||
}
|
|
||||||
return chantier ? (chantier.adresse ?? getLabel(chantier)) : (placeholder ?? "Chantier");
|
|
||||||
})() : (placeholder ?? "Chantier"))
|
|
||||||
)}
|
|
||||||
</ThemedText>
|
</ThemedText>
|
||||||
</AnimatedThemedButton>
|
</AnimatedThemedButton>
|
||||||
{isOpen && (
|
{isOpen && (
|
||||||
@@ -168,14 +111,16 @@ export default function SelectChantier(props: {
|
|||||||
+
|
+
|
||||||
</ThemedText>
|
</ThemedText>
|
||||||
</ThemedButton>
|
</ThemedButton>
|
||||||
|
<View style={styles.list}>
|
||||||
<ThemedView lvl={2} style={styles.list}>
|
{isLoaded?
|
||||||
<ScrollView contentContainerStyle={styles.chantiersList}>
|
<ScrollView contentContainerStyle={styles.chantiersList}>
|
||||||
{chantiers.map((chantier, index) =>
|
{chantiers.map((chantier, index) =>
|
||||||
renderChantier(chantier, index)
|
renderChantier(chantier, index)
|
||||||
)}
|
)}
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
</ThemedView>
|
: <ActivityIndicator style={{height:"100%"}} color="#808080" size="large" />}
|
||||||
|
</View>
|
||||||
|
|
||||||
</View>
|
</View>
|
||||||
)}
|
)}
|
||||||
</AnimatedThemedView>
|
</AnimatedThemedView>
|
||||||
@@ -278,5 +223,8 @@ const styles = StyleSheet.create({
|
|||||||
buttonAdd:{
|
buttonAdd:{
|
||||||
borderRadius: 10,
|
borderRadius: 10,
|
||||||
marginBottom: 10,
|
marginBottom: 10,
|
||||||
|
height: 30,
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user