From 2de5c6d69d71a78ea72dcb6a490eff867987bd8d Mon Sep 17 00:00:00 2001 From: Mark Wheeler Date: Wed, 24 Apr 2024 15:04:06 -0700 Subject: [PATCH] Implement shuffle --- package.json | 2 ++ src/Game.tsx | 12 ++++++++---- yarn.lock | 17 +++++++++++++++++ 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 569f941..f5cd3e4 100644 --- a/package.json +++ b/package.json @@ -11,11 +11,13 @@ }, "dependencies": { "classnames": "^2.5.1", + "lodash.shuffle": "^4.2.0", "react": "^18.2.0", "react-dom": "^18.2.0", "sass": "^1.70.0" }, "devDependencies": { + "@types/lodash.shuffle": "^4.2.9", "@types/react": "^18.2.55", "@types/react-dom": "^18.2.19", "@typescript-eslint/eslint-plugin": "^7.7.0", diff --git a/src/Game.tsx b/src/Game.tsx index 47c6782..a0dc6dc 100644 --- a/src/Game.tsx +++ b/src/Game.tsx @@ -1,5 +1,6 @@ import { useState } from "react"; import Board from "./Board.tsx"; +import shuffle from "lodash.shuffle"; import type { GameData } from "./gameData.ts"; export type WordGroup = { @@ -9,6 +10,11 @@ export type WordGroup = { }; const Game = ({ gameData }: { gameData: GameData }) => { + const [orderedWords, setOrderedWords] = useState(gameData.words); + const shuffleWords = () => { + setOrderedWords(shuffle(orderedWords)); + }; + // used to prevent double submission const [submitLocked, setSubmitLocked] = useState(false); @@ -39,7 +45,7 @@ const Game = ({ gameData }: { gameData: GameData }) => { solvedWords = solvedWords.concat(words); }); // all the words not contained in solved groups - const remainingWords = gameData.words.filter( + const remainingWords = orderedWords.filter( (word) => !solvedWords.includes(word), ); @@ -71,9 +77,7 @@ const Game = ({ gameData }: { gameData: GameData }) => { ))}
- {" "} + {" "}