diff --git a/frontend/src/components/steps/results/ResultsStep.js b/frontend/src/components/steps/results/ResultsStep.js index cc988a9..e08c0f6 100644 --- a/frontend/src/components/steps/results/ResultsStep.js +++ b/frontend/src/components/steps/results/ResultsStep.js @@ -1,7 +1,29 @@ +import { useEffect, useState } from 'react'; + import Step from '../Step'; import PlantList from './PlantList' +import Stack from '@mui/material/Stack'; +import Button from '@mui/material/Button'; +import PlantRepository from '../../../repository/PlantRepository' +import { Typography, Box } from '@mui/material'; + export default function ResultsStep(props) { + const [plants, setPlants] = useState([]); + + useEffect(() => { + const updatePlants = () => { + PlantRepository.getFilteredPlants(props.filters).then(response => { + if (response.status === 200) { + setPlants(response.data) + } + }).catch(e => { + this.setState({ plants: ["No plants found."] }); + }) + } + updatePlants()}, + [props.filters]); + function createData(name, growthForm, moisturePreferences, plantTolerances, ecosystemServices, carbonSequestration, plantingStage) { return { @@ -16,7 +38,7 @@ export default function ResultsStep(props) { } const getTableRows = () => { - return props.plants.map((plant) => { + return plants.map((plant) => { return createData( plant.display_name, plant.display_growth_form, @@ -29,8 +51,26 @@ export default function ResultsStep(props) { }) } + const downloadCSV = () => { + PlantRepository.getPlantsCSV(props.filters).then(response => { + const url = window.URL.createObjectURL(new Blob([response.data], {type : 'text/csv'})); + const link = document.createElement('a'); + link.href = url; + link.setAttribute('download', 'plants.csv'); + document.body.appendChild(link); + link.click(); + }) + } + const stepContent = (