From 494ee4eb86159cc5cf7d3006dfa66189eae7a3fd Mon Sep 17 00:00:00 2001 From: emmanueposu Date: Fri, 31 May 2024 06:03:16 -0700 Subject: [PATCH] =?UTF-8?q?Updated=20project=E2=80=99s=20file=20and=20fold?= =?UTF-8?q?er=20names=20to=20follow=20consistent=20naming=20conventions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- trivia-forge/frontend/src/App.jsx | 16 +++++----- ...nTooltip.jsx => GenerateButtonTooltip.jsx} | 4 +-- .../Components/{Nav.jsx => Navigation.jsx} | 2 +- .../{GameQuestions.jsx => QuestionsCount.jsx} | 4 +-- .../{Categories.jsx => ReviewCategories.jsx} | 8 ++--- .../{Choices.jsx => ReviewChoices.jsx} | 4 +-- .../{Questions.jsx => ReviewQuestions.jsx} | 17 ++++++----- ...gories.jsx => UnorderedCategoriesList.jsx} | 4 +-- trivia-forge/frontend/src/Models/State.jsx | 29 ------------------- trivia-forge/frontend/src/Pages/HomePage.jsx | 2 +- trivia-forge/frontend/src/Pages/LoginPage.jsx | 4 +-- .../frontend/src/Pages/SignUpPage.jsx | 4 +-- .../frontend/src/Pages/TriviaGenPage.jsx | 14 ++++----- .../frontend/src/Pages/TriviaReviewPage.jsx | 12 ++++---- .../Pages/{MyTrivia.jsx => myTriviaPage.jsx} | 20 ++++++------- .../src/{Components => hooks}/useStore.jsx | 0 .../saveGameService.jsx} | 18 ++++++------ .../triviaForgeApiService.jsx} | 10 +++---- 18 files changed, 73 insertions(+), 99 deletions(-) rename trivia-forge/frontend/src/Components/{GenBtnTooltip.jsx => GenerateButtonTooltip.jsx} (85%) rename trivia-forge/frontend/src/Components/{Nav.jsx => Navigation.jsx} (97%) rename trivia-forge/frontend/src/Components/{GameQuestions.jsx => QuestionsCount.jsx} (85%) rename trivia-forge/frontend/src/Components/{Categories.jsx => ReviewCategories.jsx} (50%) rename trivia-forge/frontend/src/Components/{Choices.jsx => ReviewChoices.jsx} (78%) rename trivia-forge/frontend/src/Components/{Questions.jsx => ReviewQuestions.jsx} (73%) rename trivia-forge/frontend/src/Components/{GameCategories.jsx => UnorderedCategoriesList.jsx} (79%) delete mode 100644 trivia-forge/frontend/src/Models/State.jsx rename trivia-forge/frontend/src/Pages/{MyTrivia.jsx => myTriviaPage.jsx} (91%) rename trivia-forge/frontend/src/{Components => hooks}/useStore.jsx (100%) rename trivia-forge/frontend/src/{Services/Services.jsx => services/saveGameService.jsx} (78%) rename trivia-forge/frontend/src/{Services/TF-db_services.jsx => services/triviaForgeApiService.jsx} (97%) diff --git a/trivia-forge/frontend/src/App.jsx b/trivia-forge/frontend/src/App.jsx index 42669cbf..ca716e82 100644 --- a/trivia-forge/frontend/src/App.jsx +++ b/trivia-forge/frontend/src/App.jsx @@ -1,13 +1,13 @@ import { useState } from 'react'; import './App.css'; import { BrowserRouter, Routes, Route } from "react-router-dom"; -import Home from "./Pages/HomePage"; -import Navigation from "./Components/Nav"; -import TriviaGenPage from './Pages/TriviaGenPage'; -import TriviaReviewPage from './Pages/TriviaReviewPage'; -import MyTrivia from './Pages/MyTrivia'; -import LoginPage from './Pages/LoginPage'; -import SignUpPage from './Pages/SignUpPage'; +import Home from "./pages/homePage"; +import Navigation from "./components/Navigation"; +import TriviaGenPage from './pages/triviaGenPage'; +import TriviaReviewPage from './pages/triviaReviewPage'; +import MyTriviaPage from './pages/myTriviaPage'; +import LoginPage from './pages/loginPage'; +import SignUpPage from './pages/signUpPage'; import React from 'react'; import 'bootstrap/dist/css/bootstrap.min.css'; @@ -28,7 +28,7 @@ function App() { } /> } /> } /> - } /> + } /> } /> } /> diff --git a/trivia-forge/frontend/src/Components/GenBtnTooltip.jsx b/trivia-forge/frontend/src/Components/GenerateButtonTooltip.jsx similarity index 85% rename from trivia-forge/frontend/src/Components/GenBtnTooltip.jsx rename to trivia-forge/frontend/src/Components/GenerateButtonTooltip.jsx index 06fbf7af..3cc08669 100644 --- a/trivia-forge/frontend/src/Components/GenBtnTooltip.jsx +++ b/trivia-forge/frontend/src/Components/GenerateButtonTooltip.jsx @@ -2,7 +2,7 @@ import Button from 'react-bootstrap/Button'; import OverlayTrigger from 'react-bootstrap/OverlayTrigger'; import Tooltip from 'react-bootstrap/Tooltip'; -function GenBtnTooltip() { +function GenerateButtonTooltip() { return ( Log in to generate a game.}> @@ -14,4 +14,4 @@ function GenBtnTooltip() { ); }; -export default GenBtnTooltip; +export default GenerateButtonTooltip; diff --git a/trivia-forge/frontend/src/Components/Nav.jsx b/trivia-forge/frontend/src/Components/Navigation.jsx similarity index 97% rename from trivia-forge/frontend/src/Components/Nav.jsx rename to trivia-forge/frontend/src/Components/Navigation.jsx index ae773db9..6ea708b4 100644 --- a/trivia-forge/frontend/src/Components/Nav.jsx +++ b/trivia-forge/frontend/src/Components/Navigation.jsx @@ -2,7 +2,7 @@ import React from "react"; import { Navbar } from "react-bootstrap"; import { Nav, Button} from "react-bootstrap"; import { useNavigate } from "react-router-dom"; -import useStore from './useStore'; +import useStore from '../hooks/useStore'; function Navigation() { const currentUser = useStore(state => state.currentUser); diff --git a/trivia-forge/frontend/src/Components/GameQuestions.jsx b/trivia-forge/frontend/src/Components/QuestionsCount.jsx similarity index 85% rename from trivia-forge/frontend/src/Components/GameQuestions.jsx rename to trivia-forge/frontend/src/Components/QuestionsCount.jsx index 17c42243..d12f06a5 100644 --- a/trivia-forge/frontend/src/Components/GameQuestions.jsx +++ b/trivia-forge/frontend/src/Components/QuestionsCount.jsx @@ -1,6 +1,6 @@ import { React} from "react"; -function GameQuestions(game) { +function QuestionsCount(game) { let categories = game?.data.categories || []; function questionCount() { let count = 0; @@ -17,4 +17,4 @@ function GameQuestions(game) { ) } -export default GameQuestions; +export default QuestionsCount; diff --git a/trivia-forge/frontend/src/Components/Categories.jsx b/trivia-forge/frontend/src/Components/ReviewCategories.jsx similarity index 50% rename from trivia-forge/frontend/src/Components/Categories.jsx rename to trivia-forge/frontend/src/Components/ReviewCategories.jsx index f5f74714..5503c377 100644 --- a/trivia-forge/frontend/src/Components/Categories.jsx +++ b/trivia-forge/frontend/src/Components/ReviewCategories.jsx @@ -1,7 +1,7 @@ import React from "react"; -import Questions from "../Components/Questions"; +import ReviewQuestions from "../components/ReviewQuestions"; -function Categories({ category, index, changeValue, isMultipleChoice }) { +function ReviewCategories({ category, index, changeValue, isMultipleChoice }) { let questions = category.questions; const path = ['categories', index]; @@ -10,10 +10,10 @@ function Categories({ category, index, changeValue, isMultipleChoice }) {

{category.title || category.name}

{questions.map((question, index) => { return ( - + ); })} ); } -export default Categories; \ No newline at end of file +export default ReviewCategories; \ No newline at end of file diff --git a/trivia-forge/frontend/src/Components/Choices.jsx b/trivia-forge/frontend/src/Components/ReviewChoices.jsx similarity index 78% rename from trivia-forge/frontend/src/Components/Choices.jsx rename to trivia-forge/frontend/src/Components/ReviewChoices.jsx index ee3a4779..588b3916 100644 --- a/trivia-forge/frontend/src/Components/Choices.jsx +++ b/trivia-forge/frontend/src/Components/ReviewChoices.jsx @@ -1,7 +1,7 @@ import React from "react"; -function Choices({ data, path, index, changeValue }) { +function ReviewChoices({ data, path, index, changeValue }) { let newPath = structuredClone(path) newPath.push('choices', index) @@ -11,4 +11,4 @@ function Choices({ data, path, index, changeValue }) { ); } -export default Choices; \ No newline at end of file +export default ReviewChoices; \ No newline at end of file diff --git a/trivia-forge/frontend/src/Components/Questions.jsx b/trivia-forge/frontend/src/Components/ReviewQuestions.jsx similarity index 73% rename from trivia-forge/frontend/src/Components/Questions.jsx rename to trivia-forge/frontend/src/Components/ReviewQuestions.jsx index f8d3052f..226f72ea 100644 --- a/trivia-forge/frontend/src/Components/Questions.jsx +++ b/trivia-forge/frontend/src/Components/ReviewQuestions.jsx @@ -1,8 +1,8 @@ import React from "react"; -import Choices from "../Components/Choices"; +import ReviewChoices from "../components/ReviewChoices"; import { Card } from "react-bootstrap"; -import { Question } from "../Models/Question"; +import { Question } from "../models/question"; //logic for button to generate new question // // @@ -11,10 +11,11 @@ import { Question } from "../Models/Question"; -function Questions({ data, path, index, changeValue, isMultipleChoice }) { +function ReviewQuestions({ data, path, index, changeValue, isMultipleChoice }) { let choices = data.choices; - let newPath = structuredClone(path) - newPath.push('questions', index) + let newPath = structuredClone(path); + const key = data.problem ? "problem" : "question"; + newPath.push('questions', index); return (
@@ -22,14 +23,14 @@ function Questions({ data, path, index, changeValue, isMultipleChoice }) {

Question

{/* //Button to generate new question somewhere in here */}
- +
{isMultipleChoice && ( <>

Choices

{choices.map((choice, index) => { return ( - + ); })} @@ -47,4 +48,4 @@ function Questions({ data, path, index, changeValue, isMultipleChoice }) {
) } -export default Questions; \ No newline at end of file +export default ReviewQuestions; \ No newline at end of file diff --git a/trivia-forge/frontend/src/Components/GameCategories.jsx b/trivia-forge/frontend/src/Components/UnorderedCategoriesList.jsx similarity index 79% rename from trivia-forge/frontend/src/Components/GameCategories.jsx rename to trivia-forge/frontend/src/Components/UnorderedCategoriesList.jsx index b590dbec..c4562a5c 100644 --- a/trivia-forge/frontend/src/Components/GameCategories.jsx +++ b/trivia-forge/frontend/src/Components/UnorderedCategoriesList.jsx @@ -1,6 +1,6 @@ import { React} from "react"; -function GameCategories(game) { +function UnorderedCategoriesList(game) { const categories = game.data.categories; return ( @@ -14,4 +14,4 @@ function GameCategories(game) { ) } -export default GameCategories; +export default UnorderedCategoriesList; diff --git a/trivia-forge/frontend/src/Models/State.jsx b/trivia-forge/frontend/src/Models/State.jsx deleted file mode 100644 index 675bd747..00000000 --- a/trivia-forge/frontend/src/Models/State.jsx +++ /dev/null @@ -1,29 +0,0 @@ -import { create } from 'zustand'; - -const useStore = create((set) => ({ - currentUser: null, - userGames: [], - currentGame: null, - - setCurrentUser: (user) => set({ currentUser: user }), - setUserGames: (games) => set({ userGames: games }), - setCurrentGame: (game) => set({ currentGame: game }), - - addGame: (game) => set((state) => ({ - userGames: [...state.userGames, game], - })), - updateGame: (game) => set((state) => ({ - userGames: state.userGames.map((g) => { - if (g.id === game.id) { - return game; - } - return g; - }), - })), - deleteGame: (game) => set((state) => ({ - userGames: state.userGames.filter((g) => g.id !== game.id), - })), -})); - - -export default useStore; \ No newline at end of file diff --git a/trivia-forge/frontend/src/Pages/HomePage.jsx b/trivia-forge/frontend/src/Pages/HomePage.jsx index 1d4cfcde..8407fec5 100644 --- a/trivia-forge/frontend/src/Pages/HomePage.jsx +++ b/trivia-forge/frontend/src/Pages/HomePage.jsx @@ -3,7 +3,7 @@ import { Button, Container, Row, Col} from 'react-bootstrap'; import '../App.css'; import { FaRegFolderOpen, FaPlusCircle, FaUserCircle, FaUserPlus } from "react-icons/fa"; import { useNavigate } from 'react-router-dom'; -import useStore from "../Components/useStore"; +import useStore from "../hooks/useStore"; function Home() { const navigate = useNavigate(); diff --git a/trivia-forge/frontend/src/Pages/LoginPage.jsx b/trivia-forge/frontend/src/Pages/LoginPage.jsx index 22c97b0e..00387c12 100644 --- a/trivia-forge/frontend/src/Pages/LoginPage.jsx +++ b/trivia-forge/frontend/src/Pages/LoginPage.jsx @@ -1,8 +1,8 @@ import React, { useState } from 'react'; import { Link, useNavigate } from "react-router-dom"; import { Form, Button, Card } from "react-bootstrap"; -import { getUser, getGames } from '../Services/TF-db_services'; -import useStore from '../Components/useStore'; +import { getUser, getGames } from '../services/triviaForgeApiService'; +import useStore from '../hooks/useStore'; function LoginPage() { const [email, setEmail] = useState(''); diff --git a/trivia-forge/frontend/src/Pages/SignUpPage.jsx b/trivia-forge/frontend/src/Pages/SignUpPage.jsx index 939cf331..0c7fd9a8 100644 --- a/trivia-forge/frontend/src/Pages/SignUpPage.jsx +++ b/trivia-forge/frontend/src/Pages/SignUpPage.jsx @@ -1,8 +1,8 @@ import React, { useState } from 'react'; import { useNavigate } from "react-router-dom"; import { Form, Button, Card } from "react-bootstrap"; -import { addUser } from '../Services/TF-db_services'; -import { User } from '../Models/User'; +import { addUser } from '../services/triviaForgeApiService'; +import { User } from '../models/user'; function SignUpPage() { // initialize variables as empty strings diff --git a/trivia-forge/frontend/src/Pages/TriviaGenPage.jsx b/trivia-forge/frontend/src/Pages/TriviaGenPage.jsx index e4f74dc6..98f0125a 100644 --- a/trivia-forge/frontend/src/Pages/TriviaGenPage.jsx +++ b/trivia-forge/frontend/src/Pages/TriviaGenPage.jsx @@ -1,15 +1,15 @@ import React, { useState } from "react"; // variables that cause the component to re-render when they change import OpenAI from "openai"; -import { Game } from "../Models/Game"; +import { Game } from "../models/game"; import { useNavigate } from "react-router-dom"; -import { Question } from "../Models/Question"; -import { Choice } from "../Models/Choice"; -import { Category } from "../Models/Category"; +import { Question } from "../models/question"; +import { Choice } from "../models/choice"; +import { Category } from "../models/category"; import { Card } from "react-bootstrap"; -import useStore from '../Components/useStore'; // global state management +import useStore from '../hooks/useStore'; // global state management import Spinner from 'react-bootstrap/Spinner'; import Button from 'react-bootstrap/Button'; -import GenBtnTooltip from "../Components/GenBtnTooltip"; +import GenerateButtonTooltip from "../components/GenerateButtonTooltip"; @@ -243,7 +243,7 @@ function TriviaGenPage() { {submitBtnLabel} ) : ( - + )} diff --git a/trivia-forge/frontend/src/Pages/TriviaReviewPage.jsx b/trivia-forge/frontend/src/Pages/TriviaReviewPage.jsx index 8dd77655..03e16e8c 100644 --- a/trivia-forge/frontend/src/Pages/TriviaReviewPage.jsx +++ b/trivia-forge/frontend/src/Pages/TriviaReviewPage.jsx @@ -1,10 +1,10 @@ import React from 'react'; import { useLocation } from 'react-router-dom'; // used to access passed state -import Categories from '../Components/Categories'; +import ReviewCategories from '../components/ReviewCategories'; import { Button } from 'react-bootstrap'; -import { AddAllForGame, UpdateAllForGame } from '../Services/Services'; +import { AddAllForGame, UpdateAllForGame } from '../services/saveGameService'; import { useNavigate } from "react-router-dom"; -import useStore from '../Components/useStore'; +import useStore from '../hooks/useStore'; import '../App.css'; function TriviaReviewPage() { @@ -15,6 +15,7 @@ function TriviaReviewPage() { let categories = game.categories; const navigate = useNavigate(); const updateGame = useStore(state => state.updateGame); + const addGame = useStore(state => state.updateGame); console.log(game) @@ -25,9 +26,10 @@ function TriviaReviewPage() { }; const HandleCreateGame = async () => { + // console.log("new:", game) + // addGame(game); await AddAllForGame(game); navigate('/myTrivia'); - }; function changeValue(path, key, value) { @@ -53,7 +55,7 @@ function TriviaReviewPage() {
- +
))} diff --git a/trivia-forge/frontend/src/Pages/MyTrivia.jsx b/trivia-forge/frontend/src/Pages/myTriviaPage.jsx similarity index 91% rename from trivia-forge/frontend/src/Pages/MyTrivia.jsx rename to trivia-forge/frontend/src/Pages/myTriviaPage.jsx index 7001f683..497f9ba7 100644 --- a/trivia-forge/frontend/src/Pages/MyTrivia.jsx +++ b/trivia-forge/frontend/src/Pages/myTriviaPage.jsx @@ -1,18 +1,18 @@ import { React, useState, useEffect } from "react"; -import { getGames, getGamesWithDetails, deleteGame } from "../Services/TF-db_services"; +import { getGames, getGamesWithDetails, deleteGame } from "../services/triviaForgeApiService"; import Card from 'react-bootstrap/Card'; import Col from 'react-bootstrap/Col'; import Row from 'react-bootstrap/Row'; import Button from 'react-bootstrap/Button'; import Spinner from 'react-bootstrap/Spinner'; -import GameCategories from "../Components/GameCategories"; -import GameQuestions from "../Components/GameQuestions"; -import Slideshow from "../Components/Slideshow"; +import UnorderedCategoriesList from "../components/UnorderedCategoriesList"; +import QuestionsCount from "../components/QuestionsCount"; +import Slideshow from "../components/Slideshow"; import Modal from 'react-bootstrap/Modal'; import { Link, useNavigate } from "react-router-dom"; -import useStore from '../Components/useStore'; +import useStore from '../hooks/useStore'; -function MyTrivia() { +function MyTriviaPage() { // const [games, setGames] = useState(null); // store list of games const [showGame, setShowGame] = useState(false); // visibility of game modal @@ -51,7 +51,7 @@ function MyTrivia() { console.log("loaded:", loaded) if (currentUser && loaded === false) { setLoaded(true); - //console.log("calling getGamesWithDetails"); + console.log("calling getGamesWithDetails"); getGamesWithDetails(currentUser.id).then(res => { setSpinnerDisplay("none") if (res.length > 0) { @@ -111,11 +111,11 @@ function MyTrivia() { Categories: - + Questions: - +
@@ -160,4 +160,4 @@ function MyTrivia() { ); }; -export default MyTrivia; \ No newline at end of file +export default MyTriviaPage; \ No newline at end of file diff --git a/trivia-forge/frontend/src/Components/useStore.jsx b/trivia-forge/frontend/src/hooks/useStore.jsx similarity index 100% rename from trivia-forge/frontend/src/Components/useStore.jsx rename to trivia-forge/frontend/src/hooks/useStore.jsx diff --git a/trivia-forge/frontend/src/Services/Services.jsx b/trivia-forge/frontend/src/services/saveGameService.jsx similarity index 78% rename from trivia-forge/frontend/src/Services/Services.jsx rename to trivia-forge/frontend/src/services/saveGameService.jsx index 3a1a4755..dedcd844 100644 --- a/trivia-forge/frontend/src/Services/Services.jsx +++ b/trivia-forge/frontend/src/services/saveGameService.jsx @@ -1,32 +1,32 @@ -import * as db from './TF-db_services'; +import * as api from './triviaForgeApiService'; export const AddAllForGame = async (game) => { try { // Add the game to the database //console.log("Adding game:", game); - const newGame = await db.addGame(game); + const newGame = await api.addGame(game); //console.log("Added game with ID:", newGame.id); // Process each category in the game's categories for (const category of game.categories) { category.gameID = newGame.id; // Link category to the game //console.log("Adding category:", category); - const newCategory = await db.addCategory(category); + const newCategory = await api.addCategory(category); //console.log("Added category with ID:", newCategory.id); // Process each question in the category's questions for (const question of category.questions) { question.categoryID = newCategory.id; // Link question to the category //console.log("Adding question:", question); - const newQuestion = await db.addQuestion(question); + const newQuestion = await api.addQuestion(question); //console.log("Added question with ID:", newQuestion.id); // Process each choice in the question's choices for (const choice of question.choices) { choice.questionID = newQuestion.id; // Link choice to the question //console.log("Adding choice:", choice); - const newChoice = await db.addChoice(choice); + const newChoice = await api.addChoice(choice); //console.log("Added choice with ID:", newChoice.id); } } @@ -41,13 +41,13 @@ export const AddAllForGame = async (game) => { }; export const UpdateAllForGame = async (game) => { - await db.editGame(game); + await api.editGame(game); game.categories.forEach(async (category) => { - await db.editCategory(category); + await api.editCategory(category); category.questions.forEach(async (question) => { - await db.editQuestion(question); + await api.editQuestion(question); question.choices.forEach(async (choice) => { - await db.editChoice(choice); + await api.editChoice(choice); }); }); }); diff --git a/trivia-forge/frontend/src/Services/TF-db_services.jsx b/trivia-forge/frontend/src/services/triviaForgeApiService.jsx similarity index 97% rename from trivia-forge/frontend/src/Services/TF-db_services.jsx rename to trivia-forge/frontend/src/services/triviaForgeApiService.jsx index 7716b0f5..54d15e1f 100644 --- a/trivia-forge/frontend/src/Services/TF-db_services.jsx +++ b/trivia-forge/frontend/src/services/triviaForgeApiService.jsx @@ -1,9 +1,9 @@ import axios from 'axios'; -import { User } from '../Models/User'; -import { Game } from '../Models/Game'; -import { Question } from '../Models/Question'; -import { Category } from '../Models/Category'; -import { Choice } from '../Models/Choice'; +import { User } from '../models/user'; +import { Game } from '../models/game'; +import { Question } from '../models/question'; +import { Category } from '../models/category'; +import { Choice } from '../models/choice'; const API_URL = 'http://127.0.0.1:5000';