Isolate RNG drafts and fix image editor lifecycle
Some checks failed
Deploy Sokko G / deploy (push) Failing after 2s
Some checks failed
Deploy Sokko G / deploy (push) Failing after 2s
This commit is contained in:
parent
7c0b72f914
commit
b470a34b2a
7 changed files with 297 additions and 50 deletions
|
|
@ -165,10 +165,20 @@ export function RngSimulatorModule({ toolboxId, moduleId, context, editing = fal
|
|||
const [occurrenceDraft, setOccurrenceDraft] = useState(null);
|
||||
const [realDrawsDraft, setRealDrawsDraft] = useState(null);
|
||||
const rateFormRef = useRef(null);
|
||||
const previousEditingRef = useRef(editing);
|
||||
const [previousEditing, setPreviousEditing] = useState(editing);
|
||||
const rateDraft = useDraftForm({ label: "", rate: RNG_SIMULATOR_DEFAULT_RATE });
|
||||
const rateFormOpen = editing || Boolean(editingRateId);
|
||||
const activeRate = data.rates.find((rate) => rate.id === data.activeRateId) || data.rates[0] || null;
|
||||
const draftKey = JSON.stringify([toolboxId, moduleId, activeRate?.id, activeRate?.occurrenceUnit]);
|
||||
const [previousDraftKey, setPreviousDraftKey] = useState(null);
|
||||
if (previousDraftKey !== draftKey) {
|
||||
setPreviousDraftKey(draftKey);
|
||||
setMultiplierDraft(null);
|
||||
setCostDraft(null);
|
||||
setOccurrenceDraft(null);
|
||||
setRealDrawsDraft(null);
|
||||
setOccurrenceUnit(activeRate?.occurrenceUnit || "perHour");
|
||||
}
|
||||
const summary = useMemo(() => activeRate ? calculateRngSummary({
|
||||
rate: activeRate.rate,
|
||||
multiplier: activeRate.multiplier,
|
||||
|
|
@ -197,14 +207,11 @@ export function RngSimulatorModule({ toolboxId, moduleId, context, editing = fal
|
|||
const averageExceededDraws = Math.max(0, Math.round(averageDrawsDelta));
|
||||
const averageDrawsTone = realDrawsSummary?.averageExceeded ? (averageExceededDraws > 0 ? "negative" : "") : "positive";
|
||||
|
||||
useEffect(() => {
|
||||
const wasEditing = previousEditingRef.current;
|
||||
if (wasEditing && !editing) setEditingRateId("");
|
||||
if (!wasEditing && editing && !editingRateId) rateDraft.reset({ label: "", rate: RNG_SIMULATOR_DEFAULT_RATE });
|
||||
previousEditingRef.current = editing;
|
||||
// Le hook useDraftForm expose reset sans identité stable; cette transition ne doit dépendre que de l'ouverture.
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [editing, editingRateId]);
|
||||
if (previousEditing !== editing) {
|
||||
setPreviousEditing(editing);
|
||||
if (!editing) setEditingRateId("");
|
||||
if (editing && !editingRateId) rateDraft.reset({ label: "", rate: RNG_SIMULATOR_DEFAULT_RATE });
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
if (!rateFormOpen) return undefined;
|
||||
|
|
@ -219,14 +226,6 @@ export function RngSimulatorModule({ toolboxId, moduleId, context, editing = fal
|
|||
return () => document.removeEventListener("pointerdown", closeOnOutsidePointer);
|
||||
}, [rateFormOpen, setEditing]);
|
||||
|
||||
useEffect(() => {
|
||||
setMultiplierDraft(null);
|
||||
setCostDraft(null);
|
||||
setOccurrenceDraft(null);
|
||||
setRealDrawsDraft(null);
|
||||
setOccurrenceUnit(activeRate?.occurrenceUnit || "perHour");
|
||||
}, [activeRate?.id, activeRate?.occurrenceUnit]);
|
||||
|
||||
function save(nextData) {
|
||||
context.setModuleData(toolboxId, moduleId, nextData, "rngSimulator");
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue