Skip to content

Commit

Permalink
Merge pull request #99 from IPHUN1989/98-correcting-es-lint-errors-on…
Browse files Browse the repository at this point in the history
…-frontend

98 correcting es lint errors on frontend
  • Loading branch information
IPHUN1989 authored Jun 21, 2024
2 parents e095fed + 4cca5a2 commit 9ad38a7
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 37 deletions.
6 changes: 6 additions & 0 deletions frontend/src/Components/BoardGameForm/BoardGameForm.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useState, useEffect } from "react";
import PropTypes from "prop-types";


const BoardGameForm = ({ onSave, onCancel }) => {
Expand Down Expand Up @@ -212,4 +213,9 @@ const BoardGameForm = ({ onSave, onCancel }) => {
);
};

BoardGameForm.propTypes = {
onSave: PropTypes.func.isRequired,
onCancel: PropTypes.func.isRequired,
};

export default BoardGameForm;
17 changes: 8 additions & 9 deletions frontend/src/Pages/GameDetails/GameDetails.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as React from "react";
import { useState, useEffect } from "react";
import { useState, useEffect, useCallback} from "react";
import { useParams } from "react-router-dom";
import ExpandMoreIcon from "@mui/icons-material/ExpandMore";
import {
Expand Down Expand Up @@ -195,7 +194,7 @@ export default function GameDetails() {
}
};

const fetchRatingForGame = async () => {
const fetchRatingForGame = useCallback(async () => {
try {
const userToken = localStorage.getItem("usertoken");
const userID = localStorage.getItem("userID");
Expand All @@ -206,15 +205,15 @@ export default function GameDetails() {
"Content-Type": "application/json",
}
: { "Content-Type": "application/json" };

const response = await fetch(
`/api/ratings/check-existence?appUserPublicID=${userID}&boardGamePublicID=${boardGamePublicID}`,
{
method: "GET",
headers: headers,
}
);

if (response.ok) {
const data = await response.json();
setCheckedRating(data);
Expand All @@ -226,7 +225,7 @@ export default function GameDetails() {
} catch (error) {
console.error("Error fetching rating: ", error);
}
};
}, [boardGame]);

const fetchBoardGame = async (id) => {
try {
Expand Down Expand Up @@ -297,9 +296,9 @@ export default function GameDetails() {
if (boardGame) {
fetchRatingForGame();
}
}, [boardGame]);
}, [boardGame, fetchRatingForGame]);

const favorizedIDs = user ? user.favoriteBoardGamePublicIDS : [];
const favoredIDs = user ? user.favoriteBoardGamePublicIDS : [];

return (
<div>
Expand Down Expand Up @@ -332,7 +331,7 @@ export default function GameDetails() {
</Typography>
<br></br>
{localStorage.getItem("username") ? (
!favorizedIDs.includes(boardGame.publicID) ? (
!favoredIDs.includes(boardGame.publicID) ? (
<div>
<Button onClick={handleAddToFavorites}>
Add to favorites
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/Pages/Login/Login.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useNavigate } from "react-router-dom";
import { useState } from "react";
import "./login.css";

const Login = ({ onCancel }) => {
const Login = () => {
const [showPassword, setShowPassword] = useState(false);

const navigate = useNavigate();
Expand Down
7 changes: 7 additions & 0 deletions frontend/src/Pages/Register/Register.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { useState } from "react";
import PropTypes from "prop-types";


const Register = ({ onSave, onCancel }) => {
const [showPassword, setShowPassword] = useState(false);
Expand Down Expand Up @@ -98,4 +100,9 @@ const Register = ({ onSave, onCancel }) => {
);
};

Register.propTypes = {
onSave: PropTypes.func.isRequired,
onCancel: PropTypes.func.isRequired,
};

export default Register;
40 changes: 13 additions & 27 deletions frontend/src/Pages/UserFavoritesSite.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React, { useEffect, useState } from 'react';
import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
import { useEffect, useState, useCallback } from 'react';
import {
Link, Accordion, AccordionSummary, AccordionDetails, Card, CardContent, Typography, Button
} from '@mui/material';
Expand All @@ -8,7 +7,6 @@ function UserFavoritesSite() {
const [user, setUser] = useState(null);
const [bgs, setBgs] = useState(null);


const removeBoardGameFromFavorites = async (userId, boardGameId) => {
try {
const userToken = localStorage.getItem("usertoken");
Expand All @@ -19,9 +17,7 @@ function UserFavoritesSite() {
}
: { "Content-Type": "application/json" };

const data = {
boardGameId
}
const data = { boardGameId };

const response = await fetch(`/api/users/favorites/${userId}`, {
method: "DELETE",
Expand All @@ -30,8 +26,6 @@ function UserFavoritesSite() {
});

if (response.ok) {
// Board game was successfully removed from favorites
// You can update the UI or display a message here
console.log('Board game removed from favorites');
location.reload();
} else {
Expand All @@ -42,9 +36,6 @@ function UserFavoritesSite() {
}
};




const userFetch = async () => {
try {
const userToken = localStorage.getItem("usertoken");
Expand Down Expand Up @@ -75,13 +66,7 @@ function UserFavoritesSite() {
userFetch();
}, []);

useEffect(() => {
if (user) {
favBoardGamesFetch();
}
}, [user]);

const favBoardGamesFetch = async () => {
const favBoardGamesFetch = useCallback(async () => {
const uuids = user.favoriteBoardGamePublicIDS;

try {
Expand All @@ -93,9 +78,7 @@ function UserFavoritesSite() {
}
: { "Content-Type": "application/json" };

const data = {
uuids
};
const data = { uuids };

const response = await fetch(`/api/games/myfavorites`, {
method: "POST",
Expand All @@ -112,7 +95,14 @@ function UserFavoritesSite() {
} catch (error) {
console.error("Error fetching user data: ", error);
}
}
}, [user]);

useEffect(() => {
if (user) {
favBoardGamesFetch();
}
}, [user, favBoardGamesFetch]);

return (
<div>
{user !== null && bgs !== null ? (
Expand All @@ -128,9 +118,7 @@ function UserFavoritesSite() {
<br />

{bgs.map((bg) => (

<Accordion key={bg.publicID}>

<AccordionSummary>
<Link border={"none"} href={`/games/${bg.publicID}`}>
{bg.gameName}
Expand All @@ -139,11 +127,9 @@ function UserFavoritesSite() {
<Button onClick={() => removeBoardGameFromFavorites(localStorage.getItem("userID"), bg.publicID)}>Delete from favorites</Button>
</AccordionSummary>
<AccordionDetails>

{user.reviews.map((userRev) => {
return bg.reviews.map((bgRev) => {
if (userRev.publicID === bgRev.publicID) {

return (
<div key={bgRev.publicID}>
<Typography variant="body2">Review:</Typography>
Expand All @@ -152,7 +138,7 @@ function UserFavoritesSite() {
</div>
);
}
return; // Return null if there's no matching review
return null; // Return null if there's no matching review
});
})}
</AccordionDetails>
Expand Down

0 comments on commit 9ad38a7

Please sign in to comment.