Skip to content

Commit

Permalink
Merge pull request #38 from emmanueposu/pbranch
Browse files Browse the repository at this point in the history
Pbranch
  • Loading branch information
demuthsa authored Jun 3, 2024
2 parents 83dbba8 + 575144d commit dc3263e
Show file tree
Hide file tree
Showing 21 changed files with 101 additions and 63 deletions.
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,16 @@
# Trivia-Forge
Trivia game generator

### About:
Trivia Forge is a web-based trivia game generator that leverages the ChatGPT API to generate trivia questions, choices, hints, and answers. Users can create their own accounts, allowing them to save and access previously created games.

<br>

### Deployment URL:
https://trivia-forge.onrender.com

<br>

### Screenshots:
![Home Page](https://yxdrsdfocuonvorowgaa.supabase.co/storage/v1/object/sign/readme.md/homepage.PNG?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1cmwiOiJyZWFkbWUubWQvaG9tZXBhZ2UuUE5HIiwiaWF0IjoxNzE3MzM3ODI5LCJleHAiOjMzMjIxODAxODI5fQ.xZmcZMzwmbCg2d4KAUV2Rljn7gKNONawS_h4Hdy0gas&t=2024-06-02T14%3A17%3A09.538Z)\
\
![Game Play](https://yxdrsdfocuonvorowgaa.supabase.co/storage/v1/object/sign/readme.md/gameplay.PNG?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1cmwiOiJyZWFkbWUubWQvZ2FtZXBsYXkuUE5HIiwiaWF0IjoxNzE3MzM4MDMxLCJleHAiOjMzMjIxODAyMDMxfQ.fVkeGYVkkaKZfHFC6EC7jtiwsEwODnaIx6enHhmouG8&t=2024-06-02T14%3A20%3A31.742Z)
9 changes: 5 additions & 4 deletions trivia-forge/backend/endpoints/category.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import os
from dotenv import load_dotenv
from flask import Blueprint, request, jsonify
from supabase import create_client, Client
from dotenv import dotenv_values

load_dotenv()

bp = Blueprint('category', __name__, url_prefix='/categories')

config = dotenv_values("./.env")
url: str = config.get('SUPABASE_URL')
key: str = config.get('SUPABASE_KEY')
url: str = os.environ.get("SUPABASE_URL")
key: str = os.environ.get("SUPABASE_KEY")
supabase: Client = create_client(url, key)


Expand Down
9 changes: 5 additions & 4 deletions trivia-forge/backend/endpoints/choice.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import os
from dotenv import load_dotenv
from flask import Blueprint, request, jsonify
from supabase import create_client, Client
from dotenv import dotenv_values

load_dotenv()

bp = Blueprint('choice', __name__, url_prefix='/choices')

config = dotenv_values("./.env")
url: str = config.get('SUPABASE_URL')
key: str = config.get('SUPABASE_KEY')
url: str = os.environ.get("SUPABASE_URL")
key: str = os.environ.get("SUPABASE_KEY")
supabase: Client = create_client(url, key)


Expand Down
10 changes: 5 additions & 5 deletions trivia-forge/backend/endpoints/game.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import os
from dotenv import load_dotenv
from flask import Blueprint, request, jsonify
from supabase import create_client, Client
from dotenv import dotenv_values


load_dotenv()

bp = Blueprint('game', __name__, url_prefix='/games')

config = dotenv_values("./.env")
url: str = config.get('SUPABASE_URL')
key: str = config.get('SUPABASE_KEY')
url: str = os.environ.get("SUPABASE_URL")
key: str = os.environ.get("SUPABASE_KEY")
supabase: Client = create_client(url, key)


Expand Down
2 changes: 1 addition & 1 deletion trivia-forge/backend/endpoints/home.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@

@bp.get('')
def get_home():
return 'Welcome to Trivia Forge!'
return 'Trivia Forge API'
9 changes: 5 additions & 4 deletions trivia-forge/backend/endpoints/question.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import os
from dotenv import load_dotenv
from flask import Blueprint, request, jsonify
from supabase import create_client, Client
from dotenv import dotenv_values

load_dotenv()

bp = Blueprint('question', __name__, url_prefix='/questions')

config = dotenv_values("./.env")
url: str = config.get('SUPABASE_URL')
key: str = config.get('SUPABASE_KEY')
url: str = os.environ.get("SUPABASE_URL")
key: str = os.environ.get("SUPABASE_KEY")
supabase: Client = create_client(url, key)


Expand Down
10 changes: 5 additions & 5 deletions trivia-forge/backend/endpoints/user.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import os
from dotenv import load_dotenv
from flask import Blueprint, request, jsonify
from supabase import create_client, Client
from dotenv import dotenv_values


load_dotenv()

bp = Blueprint('user', __name__, url_prefix='/users')

config = dotenv_values("./.env")
url: str = config.get('SUPABASE_URL')
key: str = config.get('SUPABASE_KEY')
url: str = os.environ.get("SUPABASE_URL")
key: str = os.environ.get("SUPABASE_KEY")
supabase: Client = create_client(url, key)


Expand Down
10 changes: 8 additions & 2 deletions trivia-forge/backend/main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
from flask import Flask, request, jsonify
import os
from dotenv import load_dotenv
from flask import Flask
from endpoints import home, user, game, category, question, choice
from flask_cors import CORS

load_dotenv()

host = os.environ.get("HOST")


app = Flask(__name__)
CORS(app)
Expand All @@ -15,4 +21,4 @@


if __name__ == '__main__':
app.run(debug=True)
app.run(host=host, port=5000, debug=True)
37 changes: 36 additions & 1 deletion trivia-forge/backend/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions trivia-forge/backend/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ python = "^3.10"
supabase = "^2.4.3"
flask = "^3.0.3"
python-dotenv = "^1.0.1"
flask-cors = "^4.0.1"
gunicorn = "^22.0.0"


[build-system]
Expand Down
4 changes: 0 additions & 4 deletions trivia-forge/frontend/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,9 @@ import SignUpPage from './pages/signUpPage';
import React from 'react';
import 'bootstrap/dist/css/bootstrap.min.css';

let signedIn = false;

function App() {
const [count, setCount] = useState(0)
return (

<div className="App">
<BrowserRouter>

Expand All @@ -40,7 +37,6 @@ function App() {
</footer>
</BrowserRouter>
</div>

)
}

Expand Down
6 changes: 3 additions & 3 deletions trivia-forge/frontend/src/components/Navigation.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from "react";
import { Navbar } from "react-bootstrap";
import { Nav, Button} from "react-bootstrap";
import { useNavigate } from "react-router-dom";
import { Link, useNavigate } from "react-router-dom";
import useStore from '../hooks/useStore';


Expand All @@ -20,8 +20,8 @@ function Navigation() {
<Navbar bg="dark" data-bs-theme="dark">
<Nav className="me-auto">
<Nav.Link className="navbar-brand" href="/">Home</Nav.Link>
<Nav.Link href="/triviaGen">Create New Trivia</Nav.Link>
<Nav.Link href="/myTrivia">My Trivia</Nav.Link>
<Nav.Link as={Link} to="/triviaGen">Create New Trivia</Nav.Link>
<Nav.Link as={Link} to="/myTrivia">My Trivia</Nav.Link>
</Nav>

<Nav className="me-2">
Expand Down
1 change: 1 addition & 0 deletions trivia-forge/frontend/src/main.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import ReactDOM from 'react-dom/client'
import App from './App.jsx'
import './index.css'


ReactDOM.createRoot(document.getElementById('root')).render(
<React.StrictMode>
<App />
Expand Down
2 changes: 1 addition & 1 deletion trivia-forge/frontend/src/pages/homePage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function Home() {

<Row>
<Col>
<Button variant="primary" onClick={() => navigate('/triviagen')}> <FaPlusCircle /> Create New Game </Button>
<Button variant="primary" onClick={() => navigate('/triviaGen')}> <FaPlusCircle /> Create New Game </Button>
</Col>
</Row>

Expand Down
4 changes: 2 additions & 2 deletions trivia-forge/frontend/src/pages/loginPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ function LoginPage() {
<Form onSubmit={handleSubmit} className="form-group">
<Form.Group className="mb-3" controlId="formBasicEmail">
<Form.Label>Email</Form.Label>
<Form.Control type="email" placeholder="Enter email" value={email} onChange={(e) => setEmail(e.target.value)} />
<Form.Control type="email" placeholder="Enter email" value={email} onChange={(e) => setEmail(e.target.value)} required />
</Form.Group>

<Form.Group className="mb-3" controlId="formBasicPassword">
<Form.Label>Password</Form.Label>
<Form.Control type="password" placeholder="Enter Password" value={password} onChange={(e) => setPassword(e.target.value)} />
<Form.Control type="password" placeholder="Enter Password" value={password} onChange={(e) => setPassword(e.target.value)} required />
</Form.Group>

<p>Not a member? <Link to="/signUp" className="text-decoration-none">Sign Up</Link></p>
Expand Down
2 changes: 0 additions & 2 deletions trivia-forge/frontend/src/pages/myTriviaPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,12 @@ function MyTriviaPage() {

function handleShowWarning(game) {
setCurrentGame(game);
console.log("current game", currentGame);
setShowWarning(true);
};
function handleWarningClose() {
setShowWarning(false);
};
function handleDelete() {
console.log("deleting game", currentGame);
deleteGame(currentGame).then(res => {
setUserGames(userGames.filter(g => g.id !== currentGame.id));
});
Expand Down
12 changes: 6 additions & 6 deletions trivia-forge/frontend/src/pages/signUpPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ function SignUpPage() {
// call addUser function to add new user to database
const addedUser = await addUser(user);
if (addedUser) {
alert('User added:', addedUser);
alert('Account activated!');
navigate('/');
} else {
console.error('Error adding user');
console.error('Error signing up');
}
}

Expand All @@ -41,25 +41,25 @@ function SignUpPage() {
<Form onSubmit={handleSubmit} className="form-group">
<Form.Group className="mb-3" controlId="formBasicEmail">
<Form.Label>Email address</Form.Label>
<Form.Control type="email" placeholder="Enter email" value={email} onChange={(e) => setEmail(e.target.value)} />
<Form.Control type="email" placeholder="Enter email" value={email} onChange={(e) => setEmail(e.target.value)} required />
<Form.Text className="text-muted">
We'll never share your email with anyone else.
</Form.Text>
</Form.Group>

<Form.Group className="mb-3" controlId="formBasicUsername">
<Form.Label>Username</Form.Label>
<Form.Control type="text" placeholder="Username" value={username} onChange={(e) => setUsername(e.target.value)} />
<Form.Control type="text" placeholder="Username" value={username} onChange={(e) => setUsername(e.target.value)} required />
</Form.Group>

<Form.Group className="mb-3" controlId="formBasicPassword">
<Form.Label>Password</Form.Label>
<Form.Control type="password" placeholder="Password" value={password} onChange={(e) => setPassword(e.target.value)} />
<Form.Control type="password" placeholder="Password" value={password} onChange={(e) => setPassword(e.target.value)} required />
</Form.Group>

<Form.Group className="mb-3" controlId="formBasicConfirmPassword">
<Form.Label>Confirm Password</Form.Label>
<Form.Control type="password" placeholder="Confirm Password" value={confirmPassword} onChange={(e) => setConfirmPassword(e.target.value)} />
<Form.Control type="password" placeholder="Confirm Password" value={confirmPassword} onChange={(e) => setConfirmPassword(e.target.value)} required />
</Form.Group>

<div className="d-flex justify-content-center">
Expand Down
9 changes: 0 additions & 9 deletions trivia-forge/frontend/src/pages/triviaGenPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,10 @@ function TriviaGenPage() {
}
//create a new game and category object and add category to game
//need to change third parameter to current User ID once Users can sign in.
console.log("User:", user);
let game = new Game(Title, Theme, user.id);
console.log("Game:", game);

for (let i = 0; i < categories.length; i++) {
let newCategory = new Category(categories[i].name);
console.log(newCategory.name);
game.addCategory(newCategory);
//parse response from API
let sections = responses[i]; // store trivia questions
Expand Down Expand Up @@ -138,13 +135,7 @@ function TriviaGenPage() {
newCategory.addQuestion(newQuestion);
}
}
console.log("Category Questions:", newCategory.questions);
}
console.log("Game Categories", game.categories);

// Save game to global state and local storage
console.log("test:", game)
// addGame(game);
// state property to pass data as object to new route
navigate('/review', { state: { game: game, page: 'review', isMultipleChoice: isMultipleChoice } });
//console.log(completion.choices[0].message);
Expand Down
3 changes: 0 additions & 3 deletions trivia-forge/frontend/src/pages/triviaReviewPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ function TriviaReviewPage() {
const updateGame = useStore(state => state.updateGame);
const addGame = useStore(state => state.addGame);

console.log(game)

const HandleUpdateGame = async () => {
await UpdateAllForGame(game);
updateGame(game)
Expand All @@ -43,7 +41,6 @@ function TriviaReviewPage() {
}
}


return (
<div>
<title>Trivia Review</title>
Expand Down
3 changes: 0 additions & 3 deletions trivia-forge/frontend/src/services/saveGameService.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import * as api from './triviaForgeApiService';


export const AddAllForGame = async (game) => {
console.log("start game:", game)
try {
// Add the game to the database
//console.log("Adding game:", game);
Expand Down Expand Up @@ -38,9 +37,7 @@ export const AddAllForGame = async (game) => {
}
newGame.categories.push(newCategory);
}

// Return the newly created game
console.log("end game:", newGame)
return newGame;
} catch (error) {
console.error("Error adding game, categories, questions, or choices:", error);
Expand Down
Loading

0 comments on commit dc3263e

Please sign in to comment.