fixed pool issue!
This commit is contained in:
parent
7b933effa4
commit
7693ee10b3
|
@ -12472,36 +12472,6 @@ const minimalPairs: {
|
||||||
f: "shekh",
|
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: {
|
entry: {
|
||||||
|
|
|
@ -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 { CountdownCircleTimer } from "react-countdown-circle-timer";
|
||||||
import Reward, { RewardElement } from "react-rewards";
|
import Reward, { RewardElement } from "react-rewards";
|
||||||
import Link from "../components/Link";
|
import Link from "../components/Link";
|
||||||
|
@ -25,7 +25,7 @@ type GameState<Question> = (
|
||||||
}
|
}
|
||||||
) & {
|
) & {
|
||||||
numberComplete: number;
|
numberComplete: number;
|
||||||
current: Question;
|
current: Question | undefined;
|
||||||
timerKey: number;
|
timerKey: number;
|
||||||
strikes: number;
|
strikes: number;
|
||||||
justStruck: boolean;
|
justStruck: boolean;
|
||||||
|
@ -74,10 +74,13 @@ function GameCore<Question>({
|
||||||
timeLimit: number;
|
timeLimit: number;
|
||||||
amount: 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<Question> = {
|
const initialState: GameState<Question> = {
|
||||||
mode: "intro",
|
mode: "intro",
|
||||||
numberComplete: 0,
|
numberComplete: 0,
|
||||||
current: getQuestion(),
|
current: undefined,
|
||||||
timerKey: 0,
|
timerKey: 0,
|
||||||
strikes: 0,
|
strikes: 0,
|
||||||
justStruck: false,
|
justStruck: false,
|
||||||
|
@ -91,6 +94,10 @@ function GameCore<Question>({
|
||||||
useState<GameState<Question>>(initialState);
|
useState<GameState<Question>>(initialState);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
parent.current && autoAnimate(parent.current);
|
parent.current && autoAnimate(parent.current);
|
||||||
|
setStateDangerous((s) => ({
|
||||||
|
...s,
|
||||||
|
current: getQuestion(),
|
||||||
|
}));
|
||||||
}, [parent]);
|
}, [parent]);
|
||||||
|
|
||||||
const gameReducer = (
|
const gameReducer = (
|
||||||
|
@ -173,6 +180,7 @@ function GameCore<Question>({
|
||||||
if (action.type === "quit") {
|
if (action.type === "quit") {
|
||||||
return {
|
return {
|
||||||
...initialState,
|
...initialState,
|
||||||
|
current: getQuestion(),
|
||||||
timerKey: gs.timerKey + 1,
|
timerKey: gs.timerKey + 1,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -372,7 +380,7 @@ function GameCore<Question>({
|
||||||
<ActionButtons />
|
<ActionButtons />
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
{gameRunning && (
|
{gameRunning && state.current && (
|
||||||
<Display
|
<Display
|
||||||
question={state.current}
|
question={state.current}
|
||||||
callback={(correct) =>
|
callback={(correct) =>
|
||||||
|
@ -394,7 +402,7 @@ function GameCore<Question>({
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
{state.showAnswer && state.mode === "practice" && (
|
{state.showAnswer && state.mode === "practice" && state.current && (
|
||||||
<div className="my-2">
|
<div className="my-2">
|
||||||
<div className="my-1">
|
<div className="my-1">
|
||||||
<DisplayCorrectAnswer question={state.current} />
|
<DisplayCorrectAnswer question={state.current} />
|
||||||
|
@ -423,24 +431,25 @@ function GameCore<Question>({
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
{(state.mode === "timeout" || state.mode === "fail") && (
|
{(state.mode === "timeout" || state.mode === "fail") &&
|
||||||
<div className="mb-4">
|
state.current && (
|
||||||
<h4 className="mt-4">
|
<div className="mb-4">
|
||||||
{failMessage({
|
<h4 className="mt-4">
|
||||||
numberComplete: state.numberComplete,
|
{failMessage({
|
||||||
amount,
|
numberComplete: state.numberComplete,
|
||||||
type: state.mode,
|
amount,
|
||||||
})}
|
type: state.mode,
|
||||||
</h4>
|
})}
|
||||||
<div>The correct answer was:</div>
|
</h4>
|
||||||
<div className="my-2">
|
<div>The correct answer was:</div>
|
||||||
<DisplayCorrectAnswer question={state.current} />
|
<div className="my-2">
|
||||||
|
<DisplayCorrectAnswer question={state.current} />
|
||||||
|
</div>
|
||||||
|
<div className="my-3">
|
||||||
|
<ActionButtons />
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="my-3">
|
)}
|
||||||
<ActionButtons />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
</Reward>
|
</Reward>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -36,7 +36,6 @@ export default function MinimalPairsGame({
|
||||||
minimalPairs.find((x) => x.title === level)?.pairs || []
|
minimalPairs.find((x) => x.title === level)?.pairs || []
|
||||||
);
|
);
|
||||||
function getQuestion(): Question {
|
function getQuestion(): Question {
|
||||||
console.log("getting question");
|
|
||||||
const pair = getPair();
|
const pair = getPair();
|
||||||
const selected: 0 | 1 = randFromArray([0, 1]);
|
const selected: 0 | 1 = randFromArray([0, 1]);
|
||||||
return { pair, selected };
|
return { pair, selected };
|
||||||
|
|
|
@ -24,7 +24,6 @@ export function makePool<P>(poolBase: P[], removalLaxity = 0): () => P {
|
||||||
return pick;
|
return pick;
|
||||||
}
|
}
|
||||||
const index = pool.findIndex((v) => equal(v, pick));
|
const index = pool.findIndex((v) => equal(v, pick));
|
||||||
console.log({ pool });
|
|
||||||
if (index === -1) throw new Error("could not find pick from pool");
|
if (index === -1) throw new Error("could not find pick from pool");
|
||||||
pool.splice(index, 1);
|
pool.splice(index, 1);
|
||||||
// If the pool is empty, reset it
|
// If the pool is empty, reset it
|
||||||
|
|
14
src/main.tsx
14
src/main.tsx
|
@ -19,11 +19,11 @@ const updateSW = registerSW({
|
||||||
});
|
});
|
||||||
|
|
||||||
ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render(
|
ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render(
|
||||||
<React.StrictMode>
|
// <React.StrictMode>
|
||||||
<BrowserRouter>
|
<BrowserRouter>
|
||||||
<UserProvider>
|
<UserProvider>
|
||||||
<App />
|
<App />
|
||||||
</UserProvider>
|
</UserProvider>
|
||||||
</BrowserRouter>
|
</BrowserRouter>
|
||||||
</React.StrictMode>
|
// </React.StrictMode>
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue