fini fontionnalité de anomalie, ptet changer styles

This commit is contained in:
tuanvu
2025-12-13 11:26:22 +01:00
parent 68af57a394
commit 730a9882c7
3 changed files with 99 additions and 30 deletions

View File

@@ -1,9 +1,11 @@
import { Chantier } from "@/class/class";
import { createContext, ReactNode, useContext, useMemo, useState } from "react";
import { getChantiers } from "@/services/ressourcesService";
type ChantierContextType = {
chantier: Chantier | null;
setChantier: (p: Chantier | null) => void;
syncChantier: () => Promise<void>;
};
const ChantierContext = createContext<ChantierContextType | null>(null);
@@ -14,8 +16,19 @@ type ChantierProviderProps = {
export const ChantierProvider = ({ children }: ChantierProviderProps) => {
const [chantier, setChantier] = useState<Chantier | null>(null);
const syncChantier = async () => {
if (!chantier) return;
const value = useMemo(() => ({ chantier, setChantier }), [chantier]);
const all = await getChantiers();
const updated = all.find(c => c.id === chantier.id);
if (updated) {
setChantier(updated);
}
};
const value = useMemo(() => ({ chantier, setChantier,syncChantier }), [chantier]);
return (
<ChantierContext.Provider value={value}>