diff --git a/app/frontend/src/pages/GamePage/GamePage.js b/app/frontend/src/pages/GamePage/GamePage.js index 9bea3f27..9ca1a724 100644 --- a/app/frontend/src/pages/GamePage/GamePage.js +++ b/app/frontend/src/pages/GamePage/GamePage.js @@ -15,17 +15,37 @@ const GamePage = () => { const [similarGames, setSimilarGames] = useState([]) useEffect(() => { - const fetchGame = async () => { - try { - const response = await getGame(gameId) - setGame(response.data) - setSimilarGames(response.data.similarGames) - } catch (error) { - console.error(error) - } - } - fetchGame() - }, [gameId]) + const fetchGame = async () => { + try { + const response = await getGame(gameId); + setGame(response.data); + + const similarGamesIds = response.data.similarGames; + const gamesPromises = similarGamesIds.map(id => getGame(id)); + const similarGamesResponses = await Promise.all(gamesPromises); + + const uniqueAndApprovedSimilarGames = similarGamesResponses + .map(response => response.data) + .reduce((unique, game) => { + const isUnique = !unique.some(g => g.gameId === game.gameId); + const isApproved = game.status === "APPROVED"; + if (isUnique && isApproved) { + unique.push(game); + } + return unique; + }, []); + + setSimilarGames(uniqueAndApprovedSimilarGames); + + } catch (error) { + console.error(error); + } + }; + + if (gameId) { + fetchGame(); + } + }, [gameId]); const handleRatingChange = (selectedRating) => { setRating(selectedRating) @@ -93,7 +113,7 @@ const GamePage = () => { /> ))} - @@ -139,8 +159,8 @@ const GamePage = () => {

Games You May Like:

{similarGames.map((game) => ( -
  • -