Skip to content

Commit

Permalink
saving progress
Browse files Browse the repository at this point in the history
  • Loading branch information
justinstoner2 committed May 26, 2024
1 parent 4d06733 commit 37f7dd6
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 16 deletions.
4 changes: 2 additions & 2 deletions trivia-forge/frontend/src/Components/Nav.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ function Navigation() {
<Nav.Link href="/triviaGen">Create New Trivia</Nav.Link>
<Nav.Link href="/myTrivia">My Trivia</Nav.Link>
</Nav>
<Nav style={{marginRight: ".5rem"}}>
<Nav style={{ marginRight: ".5rem" }}>
{currentUser ? (
<Button onClick={handleLogout}>
<i className="bi bi-person-circle" style={{ marginRight: ".5rem" }}></i>Logout
<i className="bi bi-person-circle" style={{ marginRight: ".5rem" }}></i>Logout: {currentUser.username}
</Button>
) : (
<Button onClick={handleShow}>
Expand Down
3 changes: 2 additions & 1 deletion trivia-forge/frontend/src/Pages/MyTrivia.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ function MyTrivia() {

// fetch game with details when the user changes
useEffect(() => {
if (currentUser && !loaded) {
console.log("loaded:", loaded)
if (currentUser && loaded === false) {
setLoaded(true);
//console.log("calling getGamesWithDetails");
getGamesWithDetails(currentUser.id).then(res => {
Expand Down
5 changes: 3 additions & 2 deletions trivia-forge/frontend/src/Pages/TriviaReviewPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ function TriviaReviewPage() {
navigate('/myTrivia');
};

const HandleCreateGame = () => {
AddAllForGame(game);
const HandleCreateGame = async () => {
await AddAllForGame(game);
navigate('/myTrivia');

};

return (
Expand Down
16 changes: 8 additions & 8 deletions trivia-forge/frontend/src/Services/Services.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,30 +26,30 @@ import { Choice } from '../Models/Choice';
export const AddAllForGame = async (game) => {
try {
// Add the game to the database
console.log("Adding game:", game);
//console.log("Adding game:", game);
const newGame = await db.addGame(game);
console.log("Added game with ID:", newGame.id);
//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);
//console.log("Adding category:", category);
const newCategory = await db.addCategory(category);
console.log("Added category with ID:", newCategory.id);
//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);
//console.log("Adding question:", question);
const newQuestion = await db.addQuestion(question);
console.log("Added question with ID:", newQuestion.id);
//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);
//console.log("Adding choice:", choice);
const newChoice = await db.addChoice(choice);
console.log("Added choice with ID:", newChoice.id);
//console.log("Added choice with ID:", newChoice.id);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions trivia-forge/frontend/src/Services/TF-db_services.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,11 @@ export const getQuestion = async (question) => {
};

export const addQuestion = async (question) => {
console.log("questionCategoryID:", question.categoryID)
//console.log("questionCategoryID:", question.categoryID)
let newQuestion = new Question(question.question, question.answer, question.hint, question.multipleChoice, question.categoryID);
try {
const response = await axios.post(`${API_URL}/questions`, newQuestion.toJsonObject());
console.log("question:", newQuestion.toJsonObject())
//console.log("question:", newQuestion.toJsonObject())
return response.data;
} catch (error) {
console.error('Failed to add question');
Expand Down Expand Up @@ -278,7 +278,7 @@ export const getChoice = async (choice) => {

export const addChoice = async (choice) => {
let newChoice = new Choice(choice.text, choice.questionID);
console.log("newChoice:", newChoice.toJsonObject())
//console.log("newChoice:", newChoice.toJsonObject())
try {
const response = await axios.post(`${API_URL}/choices`, newChoice.toJsonObject());
return response.data;
Expand Down

0 comments on commit 37f7dd6

Please sign in to comment.