blob: f6df3a8152305eddd6c7498672d981b0851f1eab (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
import React from "react";
import { GameState } from "./App";
const Tile = ({
word,
selectWordHandler,
}: {
selectWordHandler: () => void;
word: GameState["words"][number];
}) => (
<button
onClick={!word.used ? selectWordHandler : undefined}
className={`Grid-square ${
word.selected ? "Selected" : word.used ? "Removed" : ""
}`}
>
<pre>
<h1 className="Fit-text">{word.word.toUpperCase()}</h1>
</pre>
</button>
);
export const Grid = ({
selectWordHandler,
submitSelectionHandler,
gameState,
}: {
selectWordHandler: (idx: number) => void;
submitSelectionHandler: () => void;
gameState: GameState;
}) => {
const groups = gameState.groups.map(({ title, words }) => (
<div className="Completed-group">
<pre>
<h1 className="Fit-text">{title.toUpperCase()}</h1>
<h2 className="Fit-text">{words.join(", ")}</h2>
</pre>
</div>
));
const tiles = gameState.words.map((word, i) =>
!word.used ? (
<Tile
selectWordHandler={() => selectWordHandler(i)}
word={word}
key={i}
/>
) : undefined
);
return (
<div className="Grid-container">
{groups}
<div className="Grid">{tiles}</div>
{gameState.words.filter(({ selected }) => selected).length === 4 ? (
<button className="Submit-button" onClick={submitSelectionHandler}>
SUBMIT
</button>
) : undefined}
</div>
);
};
|