diff --git a/react-project/src/App.jsx b/react-project/src/App.jsx
index 18f4b0b..5e27d79 100644
--- a/react-project/src/App.jsx
+++ b/react-project/src/App.jsx
@@ -1,6 +1,7 @@
import Header from "./components/Header";
import Footer from "./components/Footer";
import Carte from "./components/Carte";
+import BarreRecherche from "./components/BarreRecherche";
import { useState, useEffect } from "react";
import "./App.css";
@@ -9,6 +10,25 @@ function App() {
const [total, setTotal] = useState(0);
const [jeux, setJeux] = useState([]);
const [chargement, setChargement] = useState(true);
+ const [titre, setTitre] = useState("");
+ const [annee, setAnnee] = useState("");
+ const [console, setConsole] = useState("");
+
+ function ajouter(e) {
+ e.preventDefault();
+ if (titre.trim() === "") return;
+ const nouveau = {
+ id: Date.now(),
+ titre,
+ annee: Number(annee),
+ console,
+ Type: "3d",
+ };
+ setJeux([...jeux, nouveau]);
+ setTitre("");
+ setAnnee("");
+ setConsole("");
+ }
const filtres = jeux.filter((j) =>
j.titre.toLowerCase().includes(recherche.toLowerCase()),
@@ -30,9 +50,7 @@ function App() {
<>
Total de likes : {total}
+ + > diff --git a/react-project/src/components/Badge.jsx b/react-project/src/components/Badge.jsx index 2a6ff9c..875faa8 100644 --- a/react-project/src/components/Badge.jsx +++ b/react-project/src/components/Badge.jsx @@ -1,5 +1,5 @@ function Badge({ Type }) { - if (Type === "2d") return null; + if (Type === "2d") return "Jeu 2D"; return Jeu 3D ; } diff --git a/react-project/src/components/BarreRecherche.jsx b/react-project/src/components/BarreRecherche.jsx index 9b48202..93948dc 100644 --- a/react-project/src/components/BarreRecherche.jsx +++ b/react-project/src/components/BarreRecherche.jsx @@ -1,38 +1,11 @@ -import { useState, useEffect } from "react"; -const [jeux, setJeux] = useState([]); -const [recherche, setRecherche] = useState(""); - -useEffect(() => { - document.title = `${jeux.length} jeux Zelda`; -}, [jeux]); - -const filtres = jeux.filter((j) => - j.titre.toLowerCase().includes(recherche.toLowerCase()), -); - const [total, setTotal] = useState(0); - -function BarreRecherche() { +function BarreRecherche({ valeur, onChange }) { return ( setRecherche(e.target.value)} + value={valeur} + onChange={onChange} /> - - {filtres.length === 0 &&Aucun jeu trouvé 😕
} - - {filtres.map((jeu) => ( -Total de likes : {total}
); } diff --git a/react-project/src/components/Carte.jsx b/react-project/src/components/Carte.jsx index ae2cdd2..c3b6105 100644 --- a/react-project/src/components/Carte.jsx +++ b/react-project/src/components/Carte.jsx @@ -15,7 +15,7 @@ function Carte(props) {
- {props.console} - {props.annee} -