From 10ae4f46ce099da10742aee552b65d5aac9a38d9 Mon Sep 17 00:00:00 2001 From: Dana Lambert Date: Tue, 19 Oct 2021 16:07:13 +1300 Subject: [PATCH] Modify frontend api call for plants to be filtered --- frontend/src/pages/MainPage.js | 3 ++- frontend/src/repository/PlantRepository.js | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/frontend/src/pages/MainPage.js b/frontend/src/pages/MainPage.js index e5351e3..929a0bb 100644 --- a/frontend/src/pages/MainPage.js +++ b/frontend/src/pages/MainPage.js @@ -19,7 +19,7 @@ export default class MainPage extends React.Component { } updatePlants() { - PlantRepsostory.getPlants().then(response => { + PlantRepsostory.getFilteredPlants(this.state.filters).then(response => { if (response.status === 200) { this.setState({ plants: response.data }); } @@ -30,6 +30,7 @@ export default class MainPage extends React.Component { updateFilterState(newFilter) { this.setState({ filters: { ...this.state.filters, ...newFilter } }) + this.updatePlants() } componentDidMount() { diff --git a/frontend/src/repository/PlantRepository.js b/frontend/src/repository/PlantRepository.js index 65c1b98..e8cccc4 100644 --- a/frontend/src/repository/PlantRepository.js +++ b/frontend/src/repository/PlantRepository.js @@ -2,8 +2,8 @@ import Repository from "./Repository"; const PlantRepsostory = { - getPlants() { - return Repository.get(`/plants/`); + getFilteredPlants(filters) { + return Repository.get(`/plants/`, { params: filters }); } }