Skip to content

Commit

Permalink
Implement shuffle
Browse files Browse the repository at this point in the history
  • Loading branch information
wheeler committed Apr 24, 2024
1 parent 65fb4ae commit 2de5c6d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
12 changes: 8 additions & 4 deletions src/Game.tsx
Original file line number Diff line number Diff line change
@@ -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 = {
Expand All @@ -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);

Expand Down Expand Up @@ -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),
);

Expand Down Expand Up @@ -71,9 +77,7 @@ const Game = ({ gameData }: { gameData: GameData }) => {
))}
</div>
<div>
<button onClick={() => alert("shuffle not implemented yet")}>
Shuffle
</button>{" "}
<button onClick={shuffleWords}>Shuffle</button>{" "}
<button
disabled={selected.length === 0}
onClick={() => {
Expand Down
17 changes: 17 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,18 @@
resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.15.tgz#596a1747233694d50f6ad8a7869fcb6f56cf5841"
integrity sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA==

"@types/lodash.shuffle@^4.2.9":
version "4.2.9"
resolved "https://registry.yarnpkg.com/@types/lodash.shuffle/-/lodash.shuffle-4.2.9.tgz#4af1b1c98dd8be8c0c6387e6a62caa476d0594a9"
integrity sha512-4siLZ4/vQH4T7Bm4254sG4n6hh9k7vd/bqfDVoeIwSha4Itu3MuoTxPX2I2Tue2JN94y7Y2I27QzwHZLdMlrBg==
dependencies:
"@types/lodash" "*"

"@types/lodash@*":
version "4.17.0"
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.17.0.tgz#d774355e41f372d5350a4d0714abb48194a489c3"
integrity sha512-t7dhREVv6dbNj0q17X12j7yDG4bD/DHYX7o5/DbDxobP0HnGPgpRz2Ej77aL7TZT3DSw13fqUTj8J4mMnqa7WA==

"@types/prop-types@*":
version "15.7.11"
resolved "https://registry.npmjs.org/@types/prop-types/-/prop-types-15.7.11.tgz"
Expand Down Expand Up @@ -1553,6 +1565,11 @@ lodash.merge@^4.6.2:
resolved "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.2.tgz"
integrity sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==

lodash.shuffle@^4.2.0:
version "4.2.0"
resolved "https://registry.yarnpkg.com/lodash.shuffle/-/lodash.shuffle-4.2.0.tgz#145b5053cf875f6f5c2a33f48b6e9948c6ec7b4b"
integrity sha512-V/rTAABKLFjoecTZjKSv+A1ZomG8hZg8hlgeG6wwQVD9AGv+10zqqSf6mFq2tVA703Zd5R0YhSuSlXA+E/Ei+Q==

loose-envify@^1.1.0, loose-envify@^1.4.0:
version "1.4.0"
resolved "https://registry.npmjs.org/loose-envify/-/loose-envify-1.4.0.tgz"
Expand Down

0 comments on commit 2de5c6d

Please sign in to comment.