From f2d3c7eb59e355780027b4e580901df051dee71d Mon Sep 17 00:00:00 2001 From: Jon Eugster Date: Mon, 24 Jul 2023 17:02:06 +0200 Subject: [PATCH] css for hidden hint button --- client/src/components/level.css | 16 +++++++-- client/src/components/level.tsx | 62 +++++++++++++++++++++------------ 2 files changed, 52 insertions(+), 26 deletions(-) diff --git a/client/src/components/level.css b/client/src/components/level.css index 05f4495..2cf436f 100644 --- a/client/src/components/level.css +++ b/client/src/components/level.css @@ -181,7 +181,7 @@ td code { } .chat { - height: calc(100% - 3.5em); + flex: 1; overflow-y: scroll; margin-left: .5em; margin-right: .5em; @@ -191,16 +191,26 @@ td code { padding-top: 0; padding-bottom: 0; overflow: hidden; + display: flex; + flex-direction: column; + } -.toggle-hidden-hints { +.chat-panel .button-row { /* width:100%; */ margin-left: .5em; margin-right: .5em; - height: 3.5em; + min-height: 2.5em; border-top: 0.1em solid #aaa; } +.chat-panel .btn { + margin-top: 1rem; + margin-bottom: 1rem; + margin-left: .5rem; + margin-right: .5rem; +} + /* .exercise-panel { display: flex; flex-flow: column; diff --git a/client/src/components/level.tsx b/client/src/components/level.tsx index 9332eea..ad7119c 100644 --- a/client/src/components/level.tsx +++ b/client/src/components/level.tsx @@ -252,10 +252,35 @@ function PlayableLevel({worldId, levelId}) { } } + function hasHiddenHints(i : number): boolean { + let step = proof[i] + + // For example if the proof isn't loaded yet + if(!step) {return false} + + return step.hints.some((hint) => hint.hidden) + } + // 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 withErr = hasInteractiveErrors(proof[k]?.errors) ? 1 : 0 + const activateHiddenHints = (ev) => { + // 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} + + // state must not be mutated, therefore we need to clone the set + let tmp = new Set(showHelp) + if (tmp.has(k - withErr)) { + tmp.delete(k - withErr) + } else { + tmp.add(k - withErr) + } + setShowHelp(tmp) + console.debug(`help: ${Array.from(tmp.values())}`) + } + return <>
@@ -292,32 +317,23 @@ function PlayableLevel({worldId, levelId}) { {level?.data?.conclusion} } - {levelId >= gameInfo.data?.worldSize[worldId] ? - : - } } -
- { - // 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} - - // state must not be mutated, therefore we need to clone the set - let tmp = new Set(showHelp) - if (tmp.has(k - withErr)) { - tmp.delete(k - withErr) - } else { - tmp.add(k - withErr) - } - setShowHelp(tmp) - console.debug(`help: ${Array.from(tmp.values())}`) - }} />} - label="Show more help!" - /> +
+ {completed && (levelId >= gameInfo.data?.worldSize[worldId] ? + : + ) + } + {hasHiddenHints(proof.length - 1) && !showHelp.has(k - withErr) && + + }