selection chantier (animation,correction) ; ajustement et amélioration du thème ; chantier provider

This commit is contained in:
Rochas
2025-12-06 22:33:01 +01:00
parent a10b2fa953
commit c581f1511f
9 changed files with 321 additions and 151 deletions

36
app/Context.tsx Normal file
View File

@@ -0,0 +1,36 @@
import { Chantier, Chef, exempleChantier } from '@/class/class';
import { createContext, ReactNode, useContext, useMemo, useState } from 'react';
type ChantierContextType = {
chantier: Chantier | null;
setChantier: (p: Chantier | null) => void;
};
const ChantierContext = createContext<ChantierContextType | null>(null);
type ChantierProviderProps = {
children: ReactNode;
};
export const ChantierProvider = ({ children }: ChantierProviderProps) => {
const [chantier, setChantier] = useState<Chantier | null>(null);
const value = useMemo(
() => ({ chantier, setChantier }),
[chantier]
);
return (
<ChantierContext.Provider value={value}>
{children}
</ChantierContext.Provider>
);
};
export const useChantier = () => {
const context = useContext(ChantierContext);
if (!context) {
throw new Error('useChantier doit être utilisé dans <ChantierProvider>');
}
return context;
};