From 7693ee10b38993fc5829282ecfc7c95f4a927c57 Mon Sep 17 00:00:00 2001 From: adueck Date: Wed, 18 Dec 2024 23:47:12 -0500 Subject: [PATCH] fixed pool issue! --- src/content/writing/minimal-pairs.ts | 30 -------------- src/games/GameCore.tsx | 53 ++++++++++++++---------- src/games/sub-cores/MinimalPairsGame.tsx | 1 - src/lib/pool.tsx | 1 - src/main.tsx | 14 +++---- 5 files changed, 38 insertions(+), 61 deletions(-) diff --git a/src/content/writing/minimal-pairs.ts b/src/content/writing/minimal-pairs.ts index 967b0b8..c3e9226 100644 --- a/src/content/writing/minimal-pairs.ts +++ b/src/content/writing/minimal-pairs.ts @@ -12472,36 +12472,6 @@ const minimalPairs: { f: "shekh", }, ], - [ - { - entry: { - ts: 1527816181, - p: "قی", - f: "qay", - e: "vomit, nausea (Arabic)", - r: 4, - c: "n. m.", - a: 3, - i: 12516, - g: "kay", - }, - f: "qay", - }, - { - entry: { - ts: 1527812753, - p: "کې", - f: "ke", - e: "in, at په ... کې, pa … ke", - r: 1, - c: "adpos.", - a: 3, - i: 13538, - g: "ke", - }, - f: "ke", - }, - ], [ { entry: { diff --git a/src/games/GameCore.tsx b/src/games/GameCore.tsx index 8e2fcca..02d3424 100644 --- a/src/games/GameCore.tsx +++ b/src/games/GameCore.tsx @@ -1,4 +1,4 @@ -import { useState, useRef, useEffect } from "react"; +import { useState, useRef, useEffect, memo } from "react"; import { CountdownCircleTimer } from "react-countdown-circle-timer"; import Reward, { RewardElement } from "react-rewards"; import Link from "../components/Link"; @@ -25,7 +25,7 @@ type GameState = ( } ) & { numberComplete: number; - current: Question; + current: Question | undefined; timerKey: number; strikes: number; justStruck: boolean; @@ -74,10 +74,13 @@ function GameCore({ timeLimit: number; amount: number; }) { + // TODO STOP THE DOUBLE POOL DIPPING !!! + // POSSIBLE SOLUTION - allow question to be undefined... then use useEffect + // to grab the first question const initialState: GameState = { mode: "intro", numberComplete: 0, - current: getQuestion(), + current: undefined, timerKey: 0, strikes: 0, justStruck: false, @@ -91,6 +94,10 @@ function GameCore({ useState>(initialState); useEffect(() => { parent.current && autoAnimate(parent.current); + setStateDangerous((s) => ({ + ...s, + current: getQuestion(), + })); }, [parent]); const gameReducer = ( @@ -173,6 +180,7 @@ function GameCore({ if (action.type === "quit") { return { ...initialState, + current: getQuestion(), timerKey: gs.timerKey + 1, }; } @@ -372,7 +380,7 @@ function GameCore({ )} - {gameRunning && ( + {gameRunning && state.current && ( @@ -394,7 +402,7 @@ function GameCore({ )} - {state.showAnswer && state.mode === "practice" && ( + {state.showAnswer && state.mode === "practice" && state.current && (
@@ -423,24 +431,25 @@ function GameCore({
)} - {(state.mode === "timeout" || state.mode === "fail") && ( -
-

- {failMessage({ - numberComplete: state.numberComplete, - amount, - type: state.mode, - })} -

-
The correct answer was:
-
- + {(state.mode === "timeout" || state.mode === "fail") && + state.current && ( +
+

+ {failMessage({ + numberComplete: state.numberComplete, + amount, + type: state.mode, + })} +

+
The correct answer was:
+
+ +
+
+ +
-
- -
-
- )} + )}
diff --git a/src/games/sub-cores/MinimalPairsGame.tsx b/src/games/sub-cores/MinimalPairsGame.tsx index 9465e31..f40ce5e 100644 --- a/src/games/sub-cores/MinimalPairsGame.tsx +++ b/src/games/sub-cores/MinimalPairsGame.tsx @@ -36,7 +36,6 @@ export default function MinimalPairsGame({ minimalPairs.find((x) => x.title === level)?.pairs || [] ); function getQuestion(): Question { - console.log("getting question"); const pair = getPair(); const selected: 0 | 1 = randFromArray([0, 1]); return { pair, selected }; diff --git a/src/lib/pool.tsx b/src/lib/pool.tsx index c919e17..5e6d3c4 100644 --- a/src/lib/pool.tsx +++ b/src/lib/pool.tsx @@ -24,7 +24,6 @@ export function makePool

(poolBase: P[], removalLaxity = 0): () => P { return pick; } const index = pool.findIndex((v) => equal(v, pick)); - console.log({ pool }); if (index === -1) throw new Error("could not find pick from pool"); pool.splice(index, 1); // If the pool is empty, reset it diff --git a/src/main.tsx b/src/main.tsx index 75c7df9..f331ae3 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -19,11 +19,11 @@ const updateSW = registerSW({ }); ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render( - - - - - - - + // + + + + + + // );