From 68a964593074f3285feb6f82e69583758b07ecb9 Mon Sep 17 00:00:00 2001 From: Melissa Date: Wed, 24 Jun 2026 16:06:57 +0200 Subject: [PATCH] added "jeux" in json and fixed small bug --- react-project/public/zelda.json | 37 +++++++++++++++++++++++++++ react-project/src/App.jsx | 44 ++++++++++++--------------------- 2 files changed, 53 insertions(+), 28 deletions(-) create mode 100644 react-project/public/zelda.json diff --git a/react-project/public/zelda.json b/react-project/public/zelda.json new file mode 100644 index 0000000..0630c91 --- /dev/null +++ b/react-project/public/zelda.json @@ -0,0 +1,37 @@ +[ + { + "id": "1", + "titre": "Oracle of ages", + "console": "Game Boy Color", + "annee": "2001", + "Type": "2d" + }, + { + "id": "2", + "titre": "Breath of the Wild", + "console": "Switch", + "annee": "2017", + "Type": "3d" + }, + { + "id": "3", + "titre": "Majora's Mask", + "console": "N64", + "annee": "2000", + "Type": "3d" + }, + { + "id": "4", + "titre": "Tears of the kingdom", + "console": "Switch", + "annee": "2023", + "Type": "3d" + }, + { + "id": "5", + "titre": "Echoes of Wisdom", + "console": "Switch", + "annee": "2024", + "Type": "3d" + } +] diff --git a/react-project/src/App.jsx b/react-project/src/App.jsx index f56d925..6220cde 100644 --- a/react-project/src/App.jsx +++ b/react-project/src/App.jsx @@ -1,47 +1,35 @@ import Header from "./components/Header"; import Footer from "./components/Footer"; import Carte from "./components/Carte"; -import { useEffect } from "react"; -import { useState } from "react"; +import { useState, useEffect } from "react"; import "./App.css"; -const jeux = [ - { - id: 1, - titre: "Oracle of ages", - console: "Game Boy Color", - annee: 2001, - Type: "2d", - }, - { - id: 2, - titre: "Breath of the Wild", - console: "Switch", - annee: 2017, - Type: "3d", - }, - { id: 3, titre: "Majora's Mask", console: "N64", annee: 2000, Type: "3d" }, - { - id: 4, - titre: "Tears of the kingdom", - console: "Switch", - annee: 2023, - Type: "3d", - }, -]; - function App() { const [recherche, setRecherche] = useState(""); const [total, setTotal] = useState(0); + const [jeux, setJeux] = useState([]); // au départ : liste vide + const [chargement, setChargement] = useState(true); const filtres = jeux.filter((j) => j.titre.toLowerCase().includes(recherche.toLowerCase()), ); useEffect(() => { - document.title = `${jeux.length} jeux Zelda`; + fetch("/zelda.json") + .then((r) => r.json()) + .then((data) => { + setJeux(data); + + setChargement(false); + }); }, []); + useEffect(() => { + document.title = `${jeux.length} jeux Zelda`; + }, [jeux]); + + if (chargement) return

Chargement…

; + return ( <>