diff --git a/trivia-forge/frontend/package-lock.json b/trivia-forge/frontend/package-lock.json index 6d389c95..da7715c2 100644 --- a/trivia-forge/frontend/package-lock.json +++ b/trivia-forge/frontend/package-lock.json @@ -16,7 +16,8 @@ "react-bootstrap": "^2.10.2", "react-dom": "^18.2.0", "react-icons": "^5.1.0", - "react-router-dom": "^6.22.3" + "react-router-dom": "^6.22.3", + "zustand": "^4.5.2" }, "devDependencies": { "@types/react": "^18.2.66", @@ -4626,6 +4627,14 @@ "punycode": "^2.1.0" } }, + "node_modules/use-sync-external-store": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/use-sync-external-store/-/use-sync-external-store-1.2.0.tgz", + "integrity": "sha512-eEgnFxGQ1Ife9bzYs6VLi8/4X6CObHMw9Qr9tPY43iKwsPw8xE8+EFsf/2cFZ5S3esXgpWgtSCtLNS41F+sKPA==", + "peerDependencies": { + "react": "^16.8.0 || ^17.0.0 || ^18.0.0" + } + }, "node_modules/vite": { "version": "5.2.9", "resolved": "https://registry.npmjs.org/vite/-/vite-5.2.9.tgz", @@ -4828,6 +4837,33 @@ "funding": { "url": "https://github.com/sponsors/sindresorhus" } + }, + "node_modules/zustand": { + "version": "4.5.2", + "resolved": "https://registry.npmjs.org/zustand/-/zustand-4.5.2.tgz", + "integrity": "sha512-2cN1tPkDVkwCy5ickKrI7vijSjPksFRfqS6237NzT0vqSsztTNnQdHw9mmN7uBdk3gceVXU0a+21jFzFzAc9+g==", + "dependencies": { + "use-sync-external-store": "1.2.0" + }, + "engines": { + "node": ">=12.7.0" + }, + "peerDependencies": { + "@types/react": ">=16.8", + "immer": ">=9.0.6", + "react": ">=16.8" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + }, + "immer": { + "optional": true + }, + "react": { + "optional": true + } + } } }, "dependencies": { @@ -7976,6 +8012,12 @@ "punycode": "^2.1.0" } }, + "use-sync-external-store": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/use-sync-external-store/-/use-sync-external-store-1.2.0.tgz", + "integrity": "sha512-eEgnFxGQ1Ife9bzYs6VLi8/4X6CObHMw9Qr9tPY43iKwsPw8xE8+EFsf/2cFZ5S3esXgpWgtSCtLNS41F+sKPA==", + "requires": {} + }, "vite": { "version": "5.2.9", "resolved": "https://registry.npmjs.org/vite/-/vite-5.2.9.tgz", @@ -8099,6 +8141,14 @@ "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz", "integrity": "sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==", "dev": true + }, + "zustand": { + "version": "4.5.2", + "resolved": "https://registry.npmjs.org/zustand/-/zustand-4.5.2.tgz", + "integrity": "sha512-2cN1tPkDVkwCy5ickKrI7vijSjPksFRfqS6237NzT0vqSsztTNnQdHw9mmN7uBdk3gceVXU0a+21jFzFzAc9+g==", + "requires": { + "use-sync-external-store": "1.2.0" + } } } } diff --git a/trivia-forge/frontend/package.json b/trivia-forge/frontend/package.json index 6ea5e672..6c4e26b9 100644 --- a/trivia-forge/frontend/package.json +++ b/trivia-forge/frontend/package.json @@ -18,7 +18,8 @@ "react-bootstrap": "^2.10.2", "react-dom": "^18.2.0", "react-icons": "^5.1.0", - "react-router-dom": "^6.22.3" + "react-router-dom": "^6.22.3", + "zustand": "^4.5.2" }, "devDependencies": { "@types/react": "^18.2.66", diff --git a/trivia-forge/frontend/src/Components/GameCategories.jsx b/trivia-forge/frontend/src/Components/GameCategories.jsx index 7c710021..0ba387d3 100644 --- a/trivia-forge/frontend/src/Components/GameCategories.jsx +++ b/trivia-forge/frontend/src/Components/GameCategories.jsx @@ -2,13 +2,16 @@ import { React, useState, useEffect } from "react"; import { getCategories } from "../Services/TF-db_services"; function GameCategories(game) { - const [categories, setCategories] = useState(null); + //const [categories, setCategories] = useState(null); + const categories = game.data.categories; - useEffect(() => { - getCategories(game.data).then( res => { - setCategories(res); - }); - }, []); + + + // useEffect(() => { + // getCategories(game.data).then(res => { + // setCategories(res); + // }); + // }, []); return ( <> diff --git a/trivia-forge/frontend/src/Components/GameQuestions.jsx b/trivia-forge/frontend/src/Components/GameQuestions.jsx index 17f92ba1..d9794321 100644 --- a/trivia-forge/frontend/src/Components/GameQuestions.jsx +++ b/trivia-forge/frontend/src/Components/GameQuestions.jsx @@ -2,34 +2,41 @@ import { React, useState, useEffect } from "react"; import { getCategories, getQuestions } from "../Services/TF-db_services"; function GameQuestions(game) { - const [categories, setCategories] = useState(null); - const [questions, setQuestions] = useState(null); - - - useEffect(() => { - getCategories(game.data).then( res => { - setCategories(res); - }); - }, []); - - useEffect(() => { - if (categories) { - const category_ids = new Set(); - for (let i = 0; i < categories.length; i++) { - category_ids.add(categories[i].id) - }; - - getQuestions(category_ids).then( res => { - setQuestions(res); - }); + //const [categories, setCategories] = useState(null); + //const [questions, setQuestions] = useState(null); + let categories = game.data.categories; + function questionCount() { + let count = 0; + for (let i = 0; i < categories.length; i++) { + count += categories[i].questions.length; } - }, [categories]); + return count; + }; + + // useEffect(() => { + // getCategories(game.data).then( res => { + // setCategories(res); + // }); + // }, []); + + // useEffect(() => { + // if (categories) { + // const category_ids = new Set(); + // for (let i = 0; i < categories.length; i++) { + // category_ids.add(categories[i].id) + // }; + + // getQuestions(category_ids).then( res => { + // setQuestions(res); + // }); + // } + // }, [categories]); return ( <> - {questions && ( - {questions.length} - )} + + {questionCount()} + > ) } diff --git a/trivia-forge/frontend/src/Components/Questions.jsx b/trivia-forge/frontend/src/Components/Questions.jsx index 014e8da3..0aac5e98 100644 --- a/trivia-forge/frontend/src/Components/Questions.jsx +++ b/trivia-forge/frontend/src/Components/Questions.jsx @@ -3,6 +3,13 @@ import Choices from "../Components/Choices"; import { Card } from "react-bootstrap"; import { Question } from "../Models/Question"; +//logic for button to generate new question +// +// +// +// + + function Questions({ data }) { let choices = data.choices; @@ -10,6 +17,7 @@ function Questions({ data }) {