Fix toolbox tutorial state across navigation
Some checks failed
Deploy Sokko G / deploy (push) Failing after 2s

This commit is contained in:
Shinuwa 2026-09-12 09:08:10 +02:00
parent 75d4d99a87
commit 898fd5286f
5 changed files with 111 additions and 11 deletions

View file

@ -0,0 +1,39 @@
// Rôle : monte la page toolbox sous StrictMode pour contrôler les demandes de tutoriel et les changements d'identité.
import { createElement, StrictMode, useState } from "react";
import { createRoot } from "react-dom/client";
import { flushSync } from "react-dom";
import { ToolboxPage } from "../../website/src/features/toolboxes/ToolboxPages.jsx";
export function mountToolboxTutorialProbe(element, siteContent) {
const root = createRoot(element);
const writes = [];
const pendingChanges = [];
let setInputs;
function Probe() {
const [inputs, updateInputs] = useState({
toolboxId: "a", pendingTutorialToolboxId: "",
toolboxes: ["a", "b", "c"].map((id) => ({ id, name: id, modules: [], tutorial: id !== "c" }))
});
setInputs = updateInputs;
return createElement(ToolboxPage, {
...inputs, siteContent, actions: {},
getToolboxGame: () => null,
getModuleData: (_toolbox, _module, fallback) => fallback,
updateModuleData: () => {},
updateToolbox: (toolbox) => {
writes.push(toolbox);
updateInputs((current) => ({ ...current, toolboxes: current.toolboxes.map((item) => item.id === toolbox.id ? toolbox : item) }));
},
setPendingTutorialToolboxId: (id) => {
pendingChanges.push(id);
updateInputs((current) => ({ ...current, pendingTutorialToolboxId: id }));
}
});
}
flushSync(() => root.render(createElement(StrictMode, null, createElement(Probe))));
return {
writes, pendingChanges,
update: (patch) => flushSync(() => setInputs((current) => ({ ...current, ...patch }))),
unmount: () => flushSync(() => root.unmount())
};
}