-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated MyTrivia page to display games
- Loading branch information
1 parent
ec2f7d6
commit b3eabb7
Showing
12 changed files
with
287 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { React, useState, useEffect } from "react"; | ||
import { getCategories } from "../Services/TF-db_services"; | ||
|
||
function GameCategories(game) { | ||
const [categories, setCategories] = useState(null); | ||
|
||
useEffect(() => { | ||
getCategories(game.data).then( res => { | ||
setCategories(res); | ||
}); | ||
}, []); | ||
|
||
return ( | ||
<> | ||
{categories && ( | ||
categories.map((category, index) => ( | ||
<span key={index}> • {category.title}</span> | ||
)) | ||
)} | ||
</> | ||
) | ||
} | ||
|
||
export default GameCategories; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
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 data = new Set(); | ||
for (let i = 0; i < categories.length; i++) { | ||
data.add(categories[i].id) | ||
}; | ||
|
||
getQuestions(data).then( res => { | ||
setQuestions(res); | ||
}); | ||
} | ||
}, [categories]); | ||
|
||
return ( | ||
<> | ||
{questions && ( | ||
<span>{questions.length}</span> | ||
)} | ||
</> | ||
) | ||
} | ||
|
||
export default GameQuestions; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { React, useState, useEffect } from "react"; | ||
import Carousel from 'react-bootstrap/Carousel'; | ||
import { getCategories, getQuestions ,getChoices } from "../Services/TF-db_services"; | ||
const slideshowBackground = "https://yxdrsdfocuonvorowgaa.supabase.co/storage/v1/object/sign/UI%20Assets/white-solid-color-background?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1cmwiOiJVSSBBc3NldHMvd2hpdGUtc29saWQtY29sb3ItYmFja2dyb3VuZCIsImlhdCI6MTcxNTE3MDQ0NywiZXhwIjo0ODY4NzcwNDQ3fQ.dPaQP-yvK0-k6wBJWrI6FqrXGEqv6Vv-a8Th99zGSyA&t=2024-05-08T12%3A14%3A08.001Z" | ||
|
||
|
||
function Slideshow(game) { | ||
const [categories, setCategories] = useState(null); | ||
const [questions, setQuestions] = useState(null); | ||
const [choices, setChoices] = useState(null); | ||
|
||
useEffect(() => { | ||
getCategories(game.data).then( res => { | ||
setCategories(res); | ||
}); | ||
}, []); | ||
|
||
useEffect(() => { | ||
if (categories) { | ||
const data = new Set(); | ||
for (let i = 0; i < categories.length; i++) { | ||
data.add(categories[i].id) | ||
}; | ||
getQuestions(data).then( res => { | ||
setQuestions(res); | ||
}); | ||
} | ||
}, [categories]); | ||
|
||
// useEffect(() => { | ||
// if (questions) { | ||
// const data = new Set(); | ||
// for (let i = 0; i < categories.length; i++) { | ||
// data.add(categories[i].id) | ||
// }; | ||
// getQuestions(data).then( res => { | ||
// setQuestions(res); | ||
// }); | ||
// } | ||
// }, [questions]); | ||
|
||
|
||
return ( | ||
<> | ||
{questions &&( | ||
<Carousel data-bs-theme="dark" className="h-100"> | ||
{questions.map((q, index) => ( | ||
<Carousel.Item key={index}> | ||
<img src={slideshowBackground} className="d-block"/> | ||
<Carousel.Caption> | ||
<h3>{q.problem}</h3> | ||
</Carousel.Caption> | ||
</Carousel.Item> | ||
))} | ||
</Carousel> | ||
)} | ||
</> | ||
) | ||
|
||
} | ||
|
||
export default Slideshow; |
2 changes: 1 addition & 1 deletion
2
trivia-forge/frontend/src/Model/Category.jsx → ...ia-forge/frontend/src/Models/Category.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
trivia-forge/frontend/src/Model/Choice.jsx → trivia-forge/frontend/src/Models/Choice.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
trivia-forge/frontend/src/Model/Game.jsx → trivia-forge/frontend/src/Models/Game.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
trivia-forge/frontend/src/Model/Question.jsx → ...ia-forge/frontend/src/Models/Question.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
trivia-forge/frontend/src/Model/User.jsx → trivia-forge/frontend/src/Models/User.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,96 @@ | ||
import React from "react"; | ||
import BootstrapTable from '../Components/BootstrapTable'; | ||
import { React, useState, useEffect } from "react"; | ||
import { getGames } from "../Services/TF-db_services"; | ||
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 GameCategories from "../Components/GameCategories"; | ||
import GameQuestions from "../Components/GameQuestions"; | ||
import Slideshow from "../Components/Slideshow"; | ||
import Modal from 'react-bootstrap/Modal'; | ||
// import BootstrapTable from '../Components/BootstrapTable'; | ||
|
||
function MyTrivia() { | ||
return ( | ||
<> | ||
<p> | ||
My Trivia Page test | ||
const [games, setGames] = useState(null); | ||
const [show, setShow] = useState(false); | ||
const [currentGame, setCurrentGame] = useState(null) | ||
|
||
useEffect(() => { | ||
getGames().then( res => { | ||
setGames(res); | ||
}); | ||
}, []); | ||
|
||
useEffect(() => { | ||
if(currentGame) { | ||
setShow(true); | ||
} | ||
}, [currentGame]); | ||
|
||
function handleClose() { | ||
setShow(false); | ||
setCurrentGame(null); | ||
} | ||
|
||
function handleShow(game) { | ||
setCurrentGame(game); | ||
} | ||
|
||
</p> | ||
<BootstrapTable /> | ||
|
||
return ( | ||
<> | ||
{games &&( | ||
games.length > 0 ? ( | ||
<Row xs={2} md={4} className="g-4 m-4"> | ||
{games.map((game, index) => ( | ||
<Col key={index}> | ||
<Card> | ||
<Card.Header as="h4">{game.title}</Card.Header> | ||
<Card.Body> | ||
<Card.Title as="h6">Category:</Card.Title> | ||
<Card.Text> | ||
<GameCategories data={game}/> | ||
</Card.Text> | ||
<Card.Title as="h6">Number of Questions:</Card.Title> | ||
<Card.Text> | ||
<GameQuestions data={game}/> | ||
</Card.Text> | ||
<div className="text-center"> | ||
<Button variant="success" onClick={() => handleShow(game)}>Play Game</Button> | ||
</div> | ||
</Card.Body> | ||
</Card> | ||
</Col> | ||
))} | ||
</Row> | ||
) : ( | ||
<p>No games to display.</p> | ||
) | ||
)} | ||
<Modal show={show} onHide={handleClose} fullscreen={true}> | ||
<Modal.Header closeButton> | ||
</Modal.Header> | ||
<Modal.Body> | ||
<Slideshow data={currentGame}/> | ||
</Modal.Body> | ||
<Modal.Footer> | ||
</Modal.Footer> | ||
</Modal> | ||
</> | ||
); | ||
|
||
} | ||
export default MyTrivia; | ||
export default MyTrivia; | ||
// function MyTrivia() { | ||
// return ( | ||
// <> | ||
// <p> | ||
// My Trivia Page test | ||
|
||
// </p> | ||
// <BootstrapTable /> | ||
// </> | ||
// ); | ||
|
||
// } | ||
// export default MyTrivia; |
Oops, something went wrong.