From cfa431f70b178ef8af77d6b5f87a9974440488a5 Mon Sep 17 00:00:00 2001 From: Lara Blersch <lb210@hdm-stuttgart.de> Date: Mon, 18 Dec 2023 13:54:10 +0100 Subject: [PATCH] #16 working on the filter menu --- .../src/components/DropDownFilter.tsx | 4 +--- growbros-frontend/src/pages/Wunschliste.tsx | 14 +++++++++++++- .../hdm/mi/growbros/service/WishListService.java | 1 + 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/growbros-frontend/src/components/DropDownFilter.tsx b/growbros-frontend/src/components/DropDownFilter.tsx index 78af840..801cc1b 100644 --- a/growbros-frontend/src/components/DropDownFilter.tsx +++ b/growbros-frontend/src/components/DropDownFilter.tsx @@ -1,4 +1,4 @@ -import React from 'react' + import { useState } from "react"; function DropDownFilter(props: PropsDropDownFilter) { @@ -6,11 +6,9 @@ function DropDownFilter(props: PropsDropDownFilter) { const options = props.options; const topic = props.topic; const [selectedOption, setSelectedOption] = useState(""); - //todo: add another const here for holding the url and sort parameter to filter the plants const handleOptionChange = (event: any) => { setSelectedOption(event.target.value); - //todo: implement a fetch here to get the filtered plants }; return ( diff --git a/growbros-frontend/src/pages/Wunschliste.tsx b/growbros-frontend/src/pages/Wunschliste.tsx index b8b0879..8c9fd64 100644 --- a/growbros-frontend/src/pages/Wunschliste.tsx +++ b/growbros-frontend/src/pages/Wunschliste.tsx @@ -6,8 +6,14 @@ function Wunschliste() { const [plants, setPlants] = useState<any[]>([]); const [error, setError] = useState(); + let sort = "" + useEffect(() => { - fetch("http://localhost:8080/api/v1/wishlist") + fetch("http://localhost:8080/api/v1/wishlist", + { + method: 'GET', + body: sort + }) .then((res) => res.json()) .then((plants) => setPlants(plants)) .catch((err) => setError(err)); @@ -25,6 +31,11 @@ function Wunschliste() { } } + /*const handleSortOptions = async () => { + //sort = DropDownFilter.options.value; + //todo: how to get current selected option? + }*/ + return ( <> @@ -37,6 +48,7 @@ function Wunschliste() { "als nächstes anpflanzbar", "jetzt anpflanzbar", ]} + // onChange={handleSortOptions()} todo: how?s /> <button onClick={handleClearWishList}>Wunschliste leeren</button> </div> diff --git a/src/main/java/hdm/mi/growbros/service/WishListService.java b/src/main/java/hdm/mi/growbros/service/WishListService.java index 0d832d6..faaccbc 100644 --- a/src/main/java/hdm/mi/growbros/service/WishListService.java +++ b/src/main/java/hdm/mi/growbros/service/WishListService.java @@ -28,6 +28,7 @@ public class WishListService { case "createdAt" -> getAllPlantsOrderedByCreatedDate(user); case "plantDate" -> getAllPlantsOrderedByNextPossiblePlantDate(user); case "currentPlantable" -> getCurrentPlantablePlants(user); + case "" -> getAllPlantsOrderedByName(user); //todo: better way to do this? default -> getAllPlantsOrderedByName(user); }; } -- GitLab