fixed bugs and installed react-router-dom
This commit is contained in:
1 parent
eb52dfb63f
commit
d78d4c1468
4 files changed
+80
-38
No files matched your search
+19
-10
@@ -12,7 +12,8 @@ function App() {
|
||||
const [chargement, setChargement] = useState(true);
|
||||
const [titre, setTitre] = useState("");
|
||||
const [annee, setAnnee] = useState("");
|
||||
const [console, setConsole] = useState("");
|
||||
const [plateforme, setPlateforme] = useState("");
|
||||
const [tri, setTri] = useState("titre");
|
||||
|
||||
function ajouter(e) {
|
||||
e.preventDefault();
|
||||
@@ -27,12 +28,16 @@ function App() {
|
||||
setJeux([...jeux, nouveau]);
|
||||
setTitre("");
|
||||
setAnnee("");
|
||||
setConsole("");
|
||||
setPlateforme("");
|
||||
}
|
||||
|
||||
const filtres = jeux.filter((j) =>
|
||||
j.titre.toLowerCase().includes(recherche.toLowerCase()),
|
||||
);
|
||||
const affiches = [...jeux]
|
||||
.filter((j) => j.titre.toLowerCase().includes(recherche.toLowerCase()))
|
||||
.sort((a, b) => {
|
||||
if (tri === "titre") return a.titre.localeCompare(b.titre);
|
||||
if (tri === "annee") return a.annee - b.annee;
|
||||
return 0;
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
fetch("/zelda.json")
|
||||
@@ -51,13 +56,17 @@ function App() {
|
||||
<Header />
|
||||
|
||||
<BarreRecherche
|
||||
value={recherche}
|
||||
valeur={recherche}
|
||||
onChange={(e) => setRecherche(e.target.value)}
|
||||
/>
|
||||
<select value={tri} onChange={(e) => setTri(e.target.value)}>
|
||||
<option value="titre">Titre (A→Z)</option>
|
||||
<option value="annee">Année</option>
|
||||
</select>
|
||||
|
||||
{filtres.length === 0 && <p>Aucun jeu trouvé 😕</p>}
|
||||
{affiches.length === 0 && <p>Aucun jeu trouvé 😕</p>}
|
||||
|
||||
{filtres.map((jeu) => (
|
||||
{affiches.map((jeu) => (
|
||||
<Carte
|
||||
key={jeu.id}
|
||||
gameId={jeu.id}
|
||||
@@ -83,8 +92,8 @@ function App() {
|
||||
placeholder="Année"
|
||||
/>
|
||||
<input
|
||||
value={console}
|
||||
onChange={(e) => setConsole(e.target.value)}
|
||||
value={plateforme}
|
||||
onChange={(e) => setPlateforme(e.target.value)}
|
||||
placeholder="Console"
|
||||
/>
|
||||
<button type="submit">Ajouter</button>
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
import Carte from "./components/Carte";
|
||||
import { useState } from "react";
|
||||
|
||||
const [tri, setTri] = useState("titre");
|
||||
|
||||
const affiches = [...filtres].sort((a, b) => {
|
||||
if (tri === "titre") return a.titre.localeCompare(b.titre);
|
||||
if (tri === "annee") return a.annee - b.annee;
|
||||
return 0;
|
||||
});
|
||||
|
||||
function Form() {
|
||||
return (
|
||||
<>
|
||||
<select value={tri} onChange={(e) => setTri(e.target.value)}>
|
||||
<option value="titre">Titre (A→Z)</option>
|
||||
<option value="annee">Année</option>
|
||||
</select>
|
||||
{affiches.map((jeu) => (
|
||||
<Carte />
|
||||
))}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export default Form;
|
||||
Reference in new issue
Block a user