diff --git a/growbros-frontend/src/components/PlantDetails.tsx b/growbros-frontend/src/components/PlantDetails.tsx index 7c6ea0db511082ca46b9237ca7d5a21fa7f5160f..a9e21b9c22aadbcd5bbb7e332fb802c0b92e9c2c 100644 --- a/growbros-frontend/src/components/PlantDetails.tsx +++ b/growbros-frontend/src/components/PlantDetails.tsx @@ -92,6 +92,7 @@ function ButtonAddToGarden({ plantId }: any) { if (response.status === 201) { console.log("Pflanze wurde erfolgreich dem Garten hinzugefügt"); } else { + console.log("Unexpected response status:", response.status); setStatus("Pflanze konnte nicht dem Garten hinzugefügt werden"); } } catch (error) { diff --git a/growbros-frontend/src/pages/Suche.tsx b/growbros-frontend/src/pages/Suche.tsx index a3f068fbb618930017f162de734b2d8c8d92acc0..f4fc97b7f9cbd7adb3978e9c463240e1c0b884e0 100644 --- a/growbros-frontend/src/pages/Suche.tsx +++ b/growbros-frontend/src/pages/Suche.tsx @@ -1,14 +1,51 @@ import "font-awesome/css/font-awesome.min.css"; import "../stylesheets/Suche.css"; import PlantsOverview from "../components/PlantsOverview"; -import { useState } from "react"; +import { useState, useEffect } from "react"; import FilterPage from "../components/FilterPage"; function Suche() { + const [randomPlants, setRandomPlants] = useState<plant[] | null>(null); + const [error, setError] = useState<null | String>(null); + const randomPlantsCount: number = 30; + const token: String = ""; + + const fetchRandomPlants = async () => { + try { + const response = await fetch( + `http://localhost:8080/api/v1/plants/randomPlants/${randomPlantsCount}`, + { + method: "GET", + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${token}`, + }, + } + ); + if (response.status == 200) { + const data = await response.json(); + setRandomPlants(data); + console.log("Succesfully fetched data"); + } else { + console.log("Unexpected response status:", response.status); + setError("Error fetching data"); + } + } catch (error) { + console.error("Error", error); + setError("Error fetching data"); + } + }; + + useEffect(() => { + fetchRandomPlants(); + }, []); + return ( <> <SearchBar /> - <PlantsOverview /> + <div> + {error ? <div>{error}</div> : <PlantsOverview plants={randomPlants} />} + </div> </> ); }