fini fontionnalité de anomalie, ptet changer styles
This commit is contained in:
@@ -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}>
|
||||
|
||||
Reference in New Issue
Block a user