add study/practice/test

This commit is contained in:
lingdocs 2022-09-02 13:27:31 +04:00
parent e9d0ae5fca
commit 18ba3b2a1f
3 changed files with 25 additions and 21 deletions

View File

@ -4,9 +4,11 @@ title: Games 🎮
import Link from "../components/Link"; import Link from "../components/Link";
There are little games/quizzes scattered throughout this book. Here you can see them all listed below. If you are <Link to="/account">logged in</Link>, when you successfully complete a game you will see a ✅ beside it. To study for a game, click on the 📚 on the right. Try to master them all! 🤓🏆 There are little games/quizzes scattered throughout this book. Here you can see them all listed below. If you are <Link to="/account">logged in</Link>, you can keep track of your progress in the games.
This is just a beginning and there are more games being added each week. When you pass a test you will see ✅ beside it and this counts towards your mastery for each section Try to master them all! 🤓🏆
There are more games being added each week...
import GamesBrowser from "../games/GamesBrowser"; import GamesBrowser from "../games/GamesBrowser";

View File

@ -38,6 +38,7 @@ function GameCore<T>({ questions, Display, timeLimit, Instructions, studyLink, i
const rewardRef = useRef<RewardElement | null>(null); const rewardRef = useRef<RewardElement | null>(null);
const parent = useRef<HTMLDivElement | null>(null); const parent = useRef<HTMLDivElement | null>(null);
const { user, pullUser, setUser } = useUser(); const { user, pullUser, setUser } = useUser();
const [mode, setMode] = useState<"practice" | "test">("test");
const [finish, setFinish] = useState<undefined | "pass" | { msg: "fail", answer: JSX.Element } | "time out">(undefined); const [finish, setFinish] = useState<undefined | "pass" | { msg: "fail", answer: JSX.Element } | "time out">(undefined);
const [strikes, setStrikes] = useState<number>(0); const [strikes, setStrikes] = useState<number>(0);
const [justStruck, setJustStruck] = useState<boolean>(false); const [justStruck, setJustStruck] = useState<boolean>(false);
@ -119,8 +120,9 @@ function GameCore<T>({ questions, Display, timeLimit, Instructions, studyLink, i
setFinish(undefined); setFinish(undefined);
setCurrent(undefined); setCurrent(undefined);
} }
function handleRestart() { function handleRestart(mode: "test" | "practice") {
logGameEvent("started game"); logGameEvent(`started game ${mode}`);
setMode(mode);
const newQuestionBox = questions(); const newQuestionBox = questions();
const { value } = newQuestionBox.next(); const { value } = newQuestionBox.next();
// just for type safety -- the generator will have at least one question // just for type safety -- the generator will have at least one question
@ -160,13 +162,13 @@ function GameCore<T>({ questions, Display, timeLimit, Instructions, studyLink, i
const gameRunning = current && finish === undefined; const gameRunning = current && finish === undefined;
return <> return <>
<div className="text-center" style={{ minHeight: "200px", zIndex: 10, position: "relative" }}> <div className="text-center" style={{ minHeight: "200px", zIndex: 10, position: "relative" }}>
<div className="progress" style={{ height: "5px" }}> {mode === "test" && <div className="progress" style={{ height: "5px" }}>
<div className={`progress-bar bg-${progressColor}`} role="progressbar" style={{ width: getProgressWidth() }} /> <div className={`progress-bar bg-${progressColor}`} role="progressbar" style={{ width: getProgressWidth() }} />
</div> </div>}
{current && <div className="d-flex flex-row justify-content-between mt-2"> {current && <div className="d-flex flex-row justify-content-between mt-2">
<StrikesDisplay strikes={strikes} /> <StrikesDisplay strikes={strikes} />
<div className="d-flex flex-row-reverse"> <div className="d-flex flex-row-reverse">
<CountdownCircleTimer {mode === "test" && <CountdownCircleTimer
key={timerKey} key={timerKey}
isPlaying={!!current && !finish} isPlaying={!!current && !finish}
size={30} size={30}
@ -176,15 +178,15 @@ function GameCore<T>({ questions, Display, timeLimit, Instructions, studyLink, i
strokeLinecap="square" strokeLinecap="square"
duration={timeLimit} duration={timeLimit}
onComplete={handleTimeOut} onComplete={handleTimeOut}
/> />}
<button onClick={handleQuit} className="btn btn-outline-secondary btn-sm mr-2">Quit</button> <button onClick={handleQuit} className="btn btn-outline-secondary btn-sm mr-2">Quit</button>
</div> </div>
</div>} </div>}
<div ref={parent}> {mode === "test" && <div ref={parent}>
{justStruck && <div className="alert alert-warning my-2" role="alert" style={{ maxWidth: "300px", margin: "0 auto" }}> {justStruck && <div className="alert alert-warning my-2" role="alert" style={{ maxWidth: "300px", margin: "0 auto" }}>
{getStrikeMessage()} {getStrikeMessage()}
</div>} </div>}
</div> </div>}
<Reward ref={rewardRef} config={{ lifetime: 130, spread: 90, elementCount: 150, zIndex: 999999999 }} type="confetti"> <Reward ref={rewardRef} config={{ lifetime: 130, spread: 90, elementCount: 150, zIndex: 999999999 }} type="confetti">
<div> <div>
{finish === undefined && {finish === undefined &&
@ -198,7 +200,11 @@ function GameCore<T>({ questions, Display, timeLimit, Instructions, studyLink, i
<Instructions /> <Instructions />
</div> </div>
<div> <div>
<button className="btn btn-primary mt-4" onClick={handleRestart}>Start</button> <Link to={studyLink}>
<button className="btn btn-danger mt-4 mx-3">Study</button>
</Link>
<button className="btn btn-warning mt-4 mx-3" onClick={() => handleRestart("practice")}>Practice</button>
<button className="btn btn-success mt-4 mx-3" onClick={() => handleRestart("test")}>Test</button>
</div> </div>
</div>) </div>)
} }
@ -206,10 +212,10 @@ function GameCore<T>({ questions, Display, timeLimit, Instructions, studyLink, i
<h4 className="mt-4"> <h4 className="mt-4">
<span role="img" aria-label="celebration">🎉</span> Finished! <span role="img" aria-label="celebration">🎉</span> Finished!
</h4> </h4>
<button className="btn btn-secondary mt-4" onClick={handleRestart}>Try Again</button> <button className="btn btn-secondary mt-4" onClick={() => handleRestart("test")}>Try Again</button>
</div>} </div>}
{(typeof finish === "object" || finish === "time out") && <div> {(typeof finish === "object" || finish === "time out") && <div>
<h4 className="mt-4">{failMessage(current?.progress, finish)}</h4> {mode === "test" && <h4 className="mt-4">{failMessage(current?.progress, finish)}</h4>}
{typeof finish === "object" && <div> {typeof finish === "object" && <div>
<div>The correct answer was:</div> <div>The correct answer was:</div>
<div className="my-2"> <div className="my-2">
@ -217,8 +223,9 @@ function GameCore<T>({ questions, Display, timeLimit, Instructions, studyLink, i
</div> </div>
</div>} </div>}
<div className="mt-3"> <div className="mt-3">
<button className="btn btn-success mr-2" onClick={handleRestart}>Try Again</button> <button className="btn btn-light mx-2" onClick={() => handleRestart("practice")}>Practice</button>
<button className="btn btn-danger ml-2" onClick={handleQuit}>Quit</button> <button className="btn btn-success mx-2" onClick={() => handleRestart("test")}>Test</button>
<button className="btn btn-danger mx-2" onClick={handleQuit}>Quit</button>
</div> </div>
<div onClick={handleQuit} className="my-3"> <div onClick={handleQuit} className="my-3">
<Link to={studyLink}> <Link to={studyLink}>

View File

@ -60,12 +60,7 @@ function ChapterDisplay({ chapter, user, handleClick, expanded }: {
</h5> </h5>
</div> </div>
<div> <div>
<h4 className={done ? "clickable" : ""}> {done && <h4></h4>}
{done ? "✅"
:
<Link to={studyLink}>{"📚"}</Link>
}
</h4>
</div> </div>
</div> </div>
<SmoothCollapse expanded={open}> <SmoothCollapse expanded={open}>