From b0ec888e650dec7d3d98ea9fc91a7273ec7061c7 Mon Sep 17 00:00:00 2001 From: IPHUN1989 Date: Fri, 21 Jun 2024 14:51:48 +0200 Subject: [PATCH 1/5] =?UTF-8?q?=F0=9F=90=9E=20fix(BoardGameForm):=20Add=20?= =?UTF-8?q?props=20validation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add props validation to onSave and onCancel --- frontend/src/Components/BoardGameForm/BoardGameForm.jsx | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/frontend/src/Components/BoardGameForm/BoardGameForm.jsx b/frontend/src/Components/BoardGameForm/BoardGameForm.jsx index 0ce77a0..ab226bb 100644 --- a/frontend/src/Components/BoardGameForm/BoardGameForm.jsx +++ b/frontend/src/Components/BoardGameForm/BoardGameForm.jsx @@ -1,4 +1,5 @@ import { useState, useEffect } from "react"; +import PropTypes from "prop-types"; const BoardGameForm = ({ onSave, onCancel }) => { @@ -212,4 +213,9 @@ const BoardGameForm = ({ onSave, onCancel }) => { ); }; +BoardGameForm.propTypes = { + onSave: PropTypes.func.isRequired, + onCancel: PropTypes.func.isRequired, +}; + export default BoardGameForm; From 67aa435c4f2cb053e24c979c9a194d9d2415d0be Mon Sep 17 00:00:00 2001 From: IPHUN1989 Date: Fri, 21 Jun 2024 14:53:04 +0200 Subject: [PATCH 2/5] =?UTF-8?q?=F0=9F=90=9E=20fix(Login):=20Remove=20unuse?= =?UTF-8?q?d=20func?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Remove unused onCancel (temporary fix) --- frontend/src/Pages/Login/Login.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/Pages/Login/Login.jsx b/frontend/src/Pages/Login/Login.jsx index 417468f..f59c61a 100644 --- a/frontend/src/Pages/Login/Login.jsx +++ b/frontend/src/Pages/Login/Login.jsx @@ -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(); From 9172aec18eb47fc6ad66be2d071572d166dcbf34 Mon Sep 17 00:00:00 2001 From: IPHUN1989 Date: Fri, 21 Jun 2024 14:54:35 +0200 Subject: [PATCH 3/5] =?UTF-8?q?=F0=9F=90=9E=20fix(Register):=20Add=20prop?= =?UTF-8?q?=20validation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add prop validation to onSave and onCancel --- frontend/src/Pages/Register/Register.jsx | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/frontend/src/Pages/Register/Register.jsx b/frontend/src/Pages/Register/Register.jsx index 75ed8f7..6776f83 100644 --- a/frontend/src/Pages/Register/Register.jsx +++ b/frontend/src/Pages/Register/Register.jsx @@ -1,4 +1,6 @@ import { useState } from "react"; +import PropTypes from "prop-types"; + const Register = ({ onSave, onCancel }) => { const [showPassword, setShowPassword] = useState(false); @@ -98,4 +100,9 @@ const Register = ({ onSave, onCancel }) => { ); }; +Register.propTypes = { + onSave: PropTypes.func.isRequired, + onCancel: PropTypes.func.isRequired, +}; + export default Register; From 546fa0ff33ac0002c0b9650d418a641e918bd266 Mon Sep 17 00:00:00 2001 From: IPHUN1989 Date: Fri, 21 Jun 2024 14:56:24 +0200 Subject: [PATCH 4/5] =?UTF-8?q?=F0=9F=90=9E=20fix(GameDetails):=20Add=20us?= =?UTF-8?q?eCallback?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add useCallback to replace old method for fetchRatingForGame --- frontend/src/Pages/GameDetails/GameDetails.jsx | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/frontend/src/Pages/GameDetails/GameDetails.jsx b/frontend/src/Pages/GameDetails/GameDetails.jsx index 1ded1c2..4ef9b32 100644 --- a/frontend/src/Pages/GameDetails/GameDetails.jsx +++ b/frontend/src/Pages/GameDetails/GameDetails.jsx @@ -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 { @@ -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"); @@ -206,7 +205,7 @@ export default function GameDetails() { "Content-Type": "application/json", } : { "Content-Type": "application/json" }; - + const response = await fetch( `/api/ratings/check-existence?appUserPublicID=${userID}&boardGamePublicID=${boardGamePublicID}`, { @@ -214,7 +213,7 @@ export default function GameDetails() { headers: headers, } ); - + if (response.ok) { const data = await response.json(); setCheckedRating(data); @@ -226,7 +225,7 @@ export default function GameDetails() { } catch (error) { console.error("Error fetching rating: ", error); } - }; + }, [boardGame]); const fetchBoardGame = async (id) => { try { @@ -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 (
@@ -332,7 +331,7 @@ export default function GameDetails() {

{localStorage.getItem("username") ? ( - !favorizedIDs.includes(boardGame.publicID) ? ( + !favoredIDs.includes(boardGame.publicID) ? (
- {user.reviews.map((userRev) => { return bg.reviews.map((bgRev) => { if (userRev.publicID === bgRev.publicID) { - return (
Review: @@ -152,7 +138,7 @@ function UserFavoritesSite() {
); } - return; // Return null if there's no matching review + return null; // Return null if there's no matching review }); })}