gestion des ressources fonctionnelle, mais pas fini

This commit is contained in:
Rochas
2025-12-14 15:00:11 +01:00
parent a2e5b1e9cf
commit 7b4e2c1130
12 changed files with 308 additions and 148 deletions

View File

@@ -23,9 +23,11 @@ export default function Home() {
<View style={{width:"100%", position: 'absolute'}}>
<SelectChantier></SelectChantier>
</View>
{chantier&&
<View style={{width:"100%", position: 'absolute',marginLeft:"50%"}}>
<SetStatus></SetStatus>
</View>
}
<ScrollView>
<View style={{paddingTop:60}}>
<ChantierSummary style={styles.summary} data={{ chantier }} />

View File

@@ -0,0 +1,33 @@
import { Reservation } from "@/class/class";
import { createContext, ReactNode, useContext, useMemo, useState } from "react";
type ReservationContextType = {
reservations: Reservation[];
setReservations: (list: Reservation[]) => void;
};
const ReservationsContext = createContext<ReservationContextType | null>(null);
type ReservationsProviderProps = {
children: ReactNode;
};
export const ReservationsProvider = ({ children }: ReservationsProviderProps) => {
const [reservations, setReservations] = useState<Reservation[]>([]);
const value = useMemo(() => ({ reservations, setReservations }), [reservations]);
return (
<ReservationsContext.Provider value={value}>
{children}
</ReservationsContext.Provider>
);
};
export const useReservations = () => {
const context = useContext(ReservationsContext);
if (!context) {
throw new Error("useRessources doit être utilisé dans <ReservationsContext>");
}
return context;
};

View File

@@ -16,9 +16,11 @@ import { Platform, UIManager } from 'react-native';
import { ChantierProvider } from "./ContextChantier";
import { UserProvider } from "./ContextUser";
import { RessourcesProvider } from "./ContextRessource";
import { ReservationsProvider } from "./ContextReservation";
import LoginScreen from "./login/login";
export const unstable_settings = {
anchor: "(tabs)",
};
@@ -60,18 +62,20 @@ export default function RootLayout() {
<UserProvider>
<ChantierProvider>
<RessourcesProvider>
<ThemeProvider value={colorScheme === "dark" ? DarkTheme : DefaultTheme}>
<Stack>
<Stack.Screen name="(tabs)" options={{ headerShown: false }} />
<Stack.Screen name="selectChantier" options={{ headerShown: false }}/>
<Stack.Screen
name="modal"
options={{ presentation: "modal", title: "Modal" }}
/>
<Stack.Screen name="login" options={{ headerShown: false }} />
</Stack>
<StatusBar style="auto" />
</ThemeProvider>
<ReservationsProvider>
<ThemeProvider value={colorScheme === "dark" ? DarkTheme : DefaultTheme}>
<Stack>
<Stack.Screen name="(tabs)" options={{ headerShown: false }} />
<Stack.Screen name="selectChantier" options={{ headerShown: false }}/>
<Stack.Screen
name="modal"
options={{ presentation: "modal", title: "Modal" }}
/>
<Stack.Screen name="login" options={{ headerShown: false }} />
</Stack>
<StatusBar style="auto" />
</ThemeProvider>
</ReservationsProvider>
</RessourcesProvider>
</ChantierProvider>
</UserProvider>