2021-10-07 10:22:44 +13:00
|
|
|
import React from 'react'
|
2021-10-07 15:39:12 +13:00
|
|
|
import { Container } from 'reactstrap';
|
|
|
|
import Stepper from '../components/Stepper'
|
2021-10-18 10:38:59 +13:00
|
|
|
import Header from '../components/Header'
|
2021-10-07 10:22:44 +13:00
|
|
|
|
|
|
|
import PlantRepsostory from '../repository/PlantRepository'
|
|
|
|
|
2021-10-18 15:46:18 +13:00
|
|
|
export default class MainPage extends React.Component {
|
2021-10-07 10:22:44 +13:00
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.state = {
|
2021-10-19 08:48:45 +13:00
|
|
|
plants: [],
|
|
|
|
filters: {}
|
2021-10-07 10:22:44 +13:00
|
|
|
}
|
2021-10-19 08:48:45 +13:00
|
|
|
|
|
|
|
this.updateFilterState = this.updateFilterState.bind(this);
|
2021-10-07 10:22:44 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
updatePlants() {
|
|
|
|
PlantRepsostory.getPlants().then(response => {
|
|
|
|
if (response.status === 200) {
|
|
|
|
this.setState({ plants: response.data });
|
|
|
|
}
|
|
|
|
}).catch(e => {
|
|
|
|
this.setState({ plants: ["No plants found."] });
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-10-19 08:48:45 +13:00
|
|
|
updateFilterState(newFilter) {
|
|
|
|
this.setState({ filters: { ...this.state.filters, ...newFilter } })
|
|
|
|
}
|
|
|
|
|
2021-10-07 10:22:44 +13:00
|
|
|
componentDidMount() {
|
|
|
|
this.updatePlants()
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
2021-10-18 15:46:18 +13:00
|
|
|
<Container fluid className='main-container p-0'>
|
2021-10-18 10:38:59 +13:00
|
|
|
<Header/>
|
2021-10-19 08:48:45 +13:00
|
|
|
<Stepper plants={this.state.plants} updateFilterState={this.updateFilterState} />
|
2021-10-07 10:22:44 +13:00
|
|
|
</Container>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|