From 6475f534e7bf457113dcc82d94bfb7ac413f71c4 Mon Sep 17 00:00:00 2001 From: Kai Stevenson Date: Fri, 13 Jun 2025 23:24:49 -0700 Subject: grouping --- frontend/README.md | 46 -------------------------------- frontend/src/App.css | 72 ++++++++++++++++++++++++++++++++++++++++++++------- frontend/src/App.tsx | 46 +++++++++++++++++++++++++++++--- frontend/src/Grid.tsx | 50 +++++++++++++++++++++++++---------- 4 files changed, 142 insertions(+), 72 deletions(-) delete mode 100644 frontend/README.md diff --git a/frontend/README.md b/frontend/README.md deleted file mode 100644 index b87cb00..0000000 --- a/frontend/README.md +++ /dev/null @@ -1,46 +0,0 @@ -# Getting Started with Create React App - -This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). - -## Available Scripts - -In the project directory, you can run: - -### `npm start` - -Runs the app in the development mode.\ -Open [http://localhost:3000](http://localhost:3000) to view it in the browser. - -The page will reload if you make edits.\ -You will also see any lint errors in the console. - -### `npm test` - -Launches the test runner in the interactive watch mode.\ -See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. - -### `npm run build` - -Builds the app for production to the `build` folder.\ -It correctly bundles React in production mode and optimizes the build for the best performance. - -The build is minified and the filenames include the hashes.\ -Your app is ready to be deployed! - -See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. - -### `npm run eject` - -**Note: this is a one-way operation. Once you `eject`, you can’t go back!** - -If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. - -Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own. - -You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it. - -## Learn More - -You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). - -To learn React, check out the [React documentation](https://reactjs.org/). diff --git a/frontend/src/App.css b/frontend/src/App.css index 4f77d97..6566fca 100644 --- a/frontend/src/App.css +++ b/frontend/src/App.css @@ -1,3 +1,11 @@ +:root { + --bg-main: #1f2526; + --bg-secondary: #364446; + --primary-element: #56d0b8; + --secondary-element: #5dd6e3; + --highlight-element: #ffec69; +} + .App { text-align: center; } @@ -28,7 +36,7 @@ } .App-bg { - background-color: #282c34; + background-color: var(--bg-main); display: flex; flex-direction: column; align-items: center; @@ -42,32 +50,61 @@ align-items: center; justify-content: center; font-size: calc(10px + 2vmin); - color: white; } -.Grid { - background: #5262816f; +.Grid-container { + background: var(--bg-main); border-radius: 20px; width: 80vmin; height: 80vmin; display: grid; + gap: 0.8vmin; /* exactly the same as the grid gap */ +} + +.Grid { + display: grid; + width: 100%; + height: auto; grid-template-columns: repeat(4, 1fr); - grid-template-rows: repeat(4, 1fr); - gap: 1%; + gap: 0.8vmin; } .Fit-text { + overflow: hidden; + text-overflow: clip; +} +.Grid-square .Fit-text { font-size: calc(10px + 1vmin); overflow: hidden; text-overflow: clip; } +.Completed-group .Fit-text { + font-size: calc(10px + 2vmin); + font-style: bold; + overflow: hidden; + text-overflow: clip; +} .Grid-square { - background: #acc1eb9d; + background: var(--secondary-element); + border: none; + border-radius: 10px; + width: 19.4vmin; + height: 19.4vmin; + font-size: 50%; + overflow: hidden; + display: flex; + align-items: center; + justify-content: center; + cursor: pointer; +} + +.Completed-group { + background: var(--secondary-element); border: none; border-radius: 10px; width: 100%; - height: 100%; + height: 19.4vmin; font-size: 50%; overflow: hidden; display: flex; @@ -76,7 +113,24 @@ } .Selected { - background: #d8deea9d; + background: var(--highlight-element); +} + +.Removed { + background: var(--bg-secondary); + cursor: default; +} + +.Submit-button { + background: var(--primary-element); + border-radius: 10px; + margin-top: 2vmin; + font-size: calc(10px + 1vmin); + font-weight: bold; + width: 100%; + height: 5vh; + border: none; + cursor: pointer; } @keyframes Logo-rotate-in { diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index f6f5296..4eb26bd 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -6,11 +6,17 @@ import { Grid } from "./Grid"; import { getWords } from "./serverHelper"; export type GameState = { - words: { word: string; selected: boolean }[]; + words: { word: string; selected: boolean; used: boolean }[]; + groups: { title: string; words: string[] }[]; }; const initializeGameState = async (): Promise => ({ - words: (await getWords()).map((word) => ({ word, selected: false })), + words: (await getWords()).map((word) => ({ + word, + selected: false, + used: false, + })), + groups: [], }); const Game = () => { @@ -39,12 +45,44 @@ const Game = () => { //FIXME don't mutate state candidateState.words[idx].selected = !candidateState.words[idx].selected; setGameState(candidateState); - console.log(`selected ${idx}`); + }; + const submitSelectionHandler = () => { + const candidateState = { ...gameState! }; + + const selectedWords = candidateState.words + .filter(({ selected }) => selected) + .map(({ word }) => word); + + if (selectedWords.length !== 4) { + return; + } + + candidateState.words = candidateState.words.map( + ({ selected, word, used }) => ({ + used: used || selected, + selected: false, + word, + }) + ); + + //mock the server response for this selection + const response = "Four letter verbs"; + const newGroup: GameState["groups"][number] = { + title: response, + words: selectedWords, + }; + candidateState.groups = [...candidateState.groups, newGroup]; + + setGameState(candidateState); }; //display logic return gameState ? ( - + ) : (

Loading...

); diff --git a/frontend/src/Grid.tsx b/frontend/src/Grid.tsx index b35f757..f6df3a8 100644 --- a/frontend/src/Grid.tsx +++ b/frontend/src/Grid.tsx @@ -9,28 +9,52 @@ const Tile = ({ word: GameState["words"][number]; }) => ( ); export const Grid = ({ selectWordHandler, - words, + submitSelectionHandler, + gameState, }: { selectWordHandler: (idx: number) => void; - words: GameState["words"]; -}) => ( -
- {new Array(16).fill(undefined).map((_, i) => ( + submitSelectionHandler: () => void; + gameState: GameState; +}) => { + const groups = gameState.groups.map(({ title, words }) => ( +
+
+        

{title.toUpperCase()}

+

{words.join(", ")}

+
+
+ )); + const tiles = gameState.words.map((word, i) => + !word.used ? ( selectWordHandler(i)} - word={words[i]} + word={word} key={i} /> - ))} -
-); + ) : undefined + ); + return ( +
+ {groups} +
{tiles}
+ {gameState.words.filter(({ selected }) => selected).length === 4 ? ( + + ) : undefined} +
+ ); +}; -- cgit v1.2.3-70-g09d2