fix for React StrictMode
This commit is contained in:
+1
-1
@@ -44,7 +44,7 @@ function App() {
|
|||||||
if (finished) {
|
if (finished) {
|
||||||
mainComponent = <GoodBye message={conclusion} />
|
mainComponent = <GoodBye message={conclusion} />
|
||||||
} else if (curLevel > 0) {
|
} else if (curLevel > 0) {
|
||||||
mainComponent = <Level nbLevels={nbLevels} level={curLevel} setCurLevel={setCurLevel} setLevelTitle={setLevelTitle} setFinished={setFinished}/>
|
mainComponent = <Level nbLevels={5} level={curLevel} setCurLevel={setCurLevel} setLevelTitle={setLevelTitle} setFinished={setFinished}/>
|
||||||
} else {
|
} else {
|
||||||
mainComponent = <Welcome setNbLevels={setNbLevels} startGame={startGame} setConclusion={setConclusion}/>
|
mainComponent = <Welcome setNbLevels={setNbLevels} startGame={startGame} setConclusion={setConclusion}/>
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -99,6 +99,8 @@ function Level({ nbLevels, level, setCurLevel, setLevelTitle, setFinished }: Lev
|
|||||||
setEditor(editor)
|
setEditor(editor)
|
||||||
setInfoProvider(infoProvider)
|
setInfoProvider(infoProvider)
|
||||||
setInfoviewApi(infoviewApi)
|
setInfoviewApi(infoviewApi)
|
||||||
|
|
||||||
|
return () => { editor.dispose() }
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
// The next function will be called when the level changes
|
// The next function will be called when the level changes
|
||||||
@@ -129,40 +131,12 @@ function Level({ nbLevels, level, setCurLevel, setLevelTitle, setFinished }: Lev
|
|||||||
}
|
}
|
||||||
}, [editor, level, leanClient])
|
}, [editor, level, leanClient])
|
||||||
|
|
||||||
function sendTactic(input) {
|
|
||||||
leanClient.sendRequest("runTactic", {tactic: input}).then(processResponse);
|
|
||||||
setLastTactic(input);
|
|
||||||
setHistory(history.concat([input]));
|
|
||||||
}
|
|
||||||
|
|
||||||
function undo() {
|
|
||||||
if (errors.length === 0) {
|
|
||||||
leanClient.sendRequest('undo', {}).then(processResponse);
|
|
||||||
}
|
|
||||||
if (history.length > 1) {
|
|
||||||
setLastTactic(history[history.length - 1]);
|
|
||||||
} else {
|
|
||||||
setLastTactic("");
|
|
||||||
};
|
|
||||||
setErrors([]);
|
|
||||||
setHistory(history.slice(0, -1));
|
|
||||||
}
|
|
||||||
|
|
||||||
function loadLevel(index) {
|
function loadLevel(index) {
|
||||||
setCompleted(false)
|
setCompleted(false)
|
||||||
setHistory([])
|
setHistory([])
|
||||||
setCurLevel(index)
|
setCurLevel(index)
|
||||||
}
|
}
|
||||||
|
|
||||||
function closeMessage() {
|
|
||||||
setMessageOpen(false)
|
|
||||||
}
|
|
||||||
|
|
||||||
function finishGame() {
|
|
||||||
setLevelTitle("")
|
|
||||||
setFinished(true)
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Grid className="level" container sx={{ mt: 3, ml: 1, mr: 1 }} columnSpacing={{ xs: 1, sm: 2, md: 3 }}>
|
<Grid className="level" container sx={{ mt: 3, ml: 1, mr: 1 }} columnSpacing={{ xs: 1, sm: 2, md: 3 }}>
|
||||||
<Grid xs={4} className="doc-panel">
|
<Grid xs={4} className="doc-panel">
|
||||||
|
|||||||
Reference in New Issue
Block a user