From 87f134c9f2714593890a530221df429122c4398b Mon Sep 17 00:00:00 2001 From: Kai Stevenson Date: Tue, 10 Jun 2025 23:50:09 -0700 Subject: init --- frontend/src/App.tsx | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 frontend/src/App.tsx (limited to 'frontend/src/App.tsx') diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx new file mode 100644 index 0000000..f6f5296 --- /dev/null +++ b/frontend/src/App.tsx @@ -0,0 +1,64 @@ +import React, { useEffect, useState } from "react"; +import logo from "./kaistevenson.svg"; +import "./App.css"; + +import { Grid } from "./Grid"; +import { getWords } from "./serverHelper"; + +export type GameState = { + words: { word: string; selected: boolean }[]; +}; + +const initializeGameState = async (): Promise => ({ + words: (await getWords()).map((word) => ({ word, selected: false })), +}); + +const Game = () => { + //state + const [gameState, setGameState] = useState(undefined); + + //initialize + useEffect(() => { + if (!gameState) { + initializeGameState() + .then((state) => setGameState(state)) + .catch(console.error); + } + }); + + //handlers + const selectWordHandler = (idx: number) => { + const candidateState = { ...gameState! }; + if (candidateState.words.filter((word) => word.selected).length === 4) { + if (!candidateState.words[idx].selected) { + //if we've already selected 4 words and we would select another, + //do nothing + return; + } + } + //FIXME don't mutate state + candidateState.words[idx].selected = !candidateState.words[idx].selected; + setGameState(candidateState); + console.log(`selected ${idx}`); + }; + + //display logic + return gameState ? ( + + ) : ( +

Loading...

+ ); +}; + +export const App = () => ( +
+
+
+ logo +
+
+ +
+
+
+); -- cgit v1.2.3-70-g09d2