diff --git a/react-project/public/zelda.json b/react-project/public/zelda.json index 0630c91..91a61b4 100644 --- a/react-project/public/zelda.json +++ b/react-project/public/zelda.json @@ -4,34 +4,39 @@ "titre": "Oracle of ages", "console": "Game Boy Color", "annee": "2001", - "Type": "2d" + "Type": "2d", + "like": 0 }, { "id": "2", "titre": "Breath of the Wild", "console": "Switch", "annee": "2017", - "Type": "3d" + "Type": "3d", + "like": 0 }, { "id": "3", "titre": "Majora's Mask", "console": "N64", "annee": "2000", - "Type": "3d" + "Type": "3d", + "like": 0 }, { "id": "4", "titre": "Tears of the kingdom", "console": "Switch", "annee": "2023", - "Type": "3d" + "Type": "3d", + "like": 0 }, { "id": "5", "titre": "Echoes of Wisdom", "console": "Switch", "annee": "2024", - "Type": "3d" + "Type": "3d", + "like": 0 } ] diff --git a/react-project/src/components/Carte.jsx b/react-project/src/components/Carte.jsx index 6d40d24..daf975a 100644 --- a/react-project/src/components/Carte.jsx +++ b/react-project/src/components/Carte.jsx @@ -1,16 +1,7 @@ -import { useEffect } from "react"; import Badge from "./Badge"; -import { useState } from "react"; import { Link } from "react-router-dom"; function Carte(props) { - const [likes, setLikes] = useState( - () => Number(localStorage.getItem("likes-" + props.gameId)) || 0, - ); - useEffect(() => { - localStorage.setItem("likes-" + props.gameId, likes); - }, [likes]); - return (

{props.titre}

@@ -18,14 +9,8 @@ function Carte(props) { {props.console} - {props.annee} -

Voir les détails - + +
); diff --git a/react-project/src/pages/Accueil.jsx b/react-project/src/pages/Accueil.jsx index d33f44c..de6ab20 100644 --- a/react-project/src/pages/Accueil.jsx +++ b/react-project/src/pages/Accueil.jsx @@ -15,6 +15,9 @@ function Accueil({ jeux, setJeux, likes, onLike }) { const anneeMoyenne = nbJeux ? Math.round(jeux.reduce((s, j) => s + Number(j.annee), 0) / nbJeux) : 0; + function supprimer(id) { + setJeux(jeux.filter((j) => j.id !== id)); + } const top = [...jeux] .sort((a, b) => (likes[b.id] || 0) - (likes[a.id] || 0)) @@ -63,7 +66,7 @@ function Accueil({ jeux, setJeux, likes, onLike }) { {affiches.length === 0 &&

Aucun jeu trouvé 😕

} -
+
{top.map((j, index) => ( @@ -73,7 +76,7 @@ function Accueil({ jeux, setJeux, likes, onLike }) { ))}
-
+
{affiches.map((jeu) => ( onLike(jeu.id)} + onDelete={() => supprimer(jeu.id)} /> ))} -
+

{nbJeux} jeux · {totalLikes} likes · année moyenne {anneeMoyenne}

-
+
-
+
);