fix toggle help in presence of errors
This commit is contained in:
@@ -335,7 +335,7 @@ export function hasErrors(diags: Diagnostic[]) {
|
|||||||
|
|
||||||
// TODO: Didn't manage to unify this with the one above
|
// TODO: Didn't manage to unify this with the one above
|
||||||
export function hasInteractiveErrors (diags: InteractiveDiagnostic[]) {
|
export function hasInteractiveErrors (diags: InteractiveDiagnostic[]) {
|
||||||
return diags.some(
|
return (typeof diags !== 'undefined') && diags.some(
|
||||||
(d) => (d.severity == DiagnosticSeverity.Error ) // || d.severity == DiagnosticSeverity.Warning
|
(d) => (d.severity == DiagnosticSeverity.Error ) // || d.severity == DiagnosticSeverity.Warning
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -240,7 +240,9 @@ function PlayableLevel({worldId, levelId}) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If the last step has errors, we want to treat it as if it is part of the second-to-last step
|
||||||
let k = proof.length - 1
|
let k = proof.length - 1
|
||||||
|
let withErr = hasInteractiveErrors(proof[k]?.errors) ? 1 : 0
|
||||||
|
|
||||||
return <>
|
return <>
|
||||||
<div style={level.isLoading ? null : {display: "none"}} className="app-content loading"><CircularProgress /></div>
|
<div style={level.isLoading ? null : {display: "none"}} className="app-content loading"><CircularProgress /></div>
|
||||||
@@ -260,7 +262,7 @@ function PlayableLevel({worldId, levelId}) {
|
|||||||
{proof.map((step, i) => {
|
{proof.map((step, i) => {
|
||||||
// It the last step has errors, it will have the same hints
|
// It the last step has errors, it will have the same hints
|
||||||
// as the second-to-last step. Therefore we should not display them.
|
// as the second-to-last step. Therefore we should not display them.
|
||||||
if (!(i == proof.length - 1 && hasInteractiveErrors(step.errors))) {
|
if (!(i == proof.length - 1 && withErr)) {
|
||||||
// TODO: Should not use index as key.
|
// TODO: Should not use index as key.
|
||||||
return <Hints key={`hints-${i}`}
|
return <Hints key={`hints-${i}`}
|
||||||
hints={step.hints} showHidden={showHelp.has(i)} step={i}
|
hints={step.hints} showHidden={showHelp.has(i)} step={i}
|
||||||
@@ -287,17 +289,17 @@ function PlayableLevel({worldId, levelId}) {
|
|||||||
</div>
|
</div>
|
||||||
<div className="toggle-hidden-hints">
|
<div className="toggle-hidden-hints">
|
||||||
<FormControlLabel
|
<FormControlLabel
|
||||||
control={<Switch checked={showHelp.has(proof.length - 1)} onChange={(ev) => {
|
control={<Switch checked={showHelp.has(k - withErr)} onChange={(ev) => {
|
||||||
console.debug(proof.length)
|
// If the last step (`k`) has errors, we want the hidden hints from the
|
||||||
|
// second-to-last step to be affected
|
||||||
if (!(proof.length)) {return}
|
if (!(proof.length)) {return}
|
||||||
|
|
||||||
let k = proof.length - 1
|
|
||||||
// state must not be mutated, therefore we need to clone the set
|
// state must not be mutated, therefore we need to clone the set
|
||||||
let tmp = new Set(showHelp)
|
let tmp = new Set(showHelp)
|
||||||
if (tmp.has(k)) {
|
if (tmp.has(k - withErr)) {
|
||||||
tmp.delete(k)
|
tmp.delete(k - withErr)
|
||||||
} else {
|
} else {
|
||||||
tmp.add(k)
|
tmp.add(k - withErr)
|
||||||
}
|
}
|
||||||
setShowHelp(tmp)
|
setShowHelp(tmp)
|
||||||
console.debug(`help: ${Array.from(tmp.values())}`)
|
console.debug(`help: ${Array.from(tmp.values())}`)
|
||||||
|
|||||||
Reference in New Issue
Block a user