import React from 'react' import { Container, Row, Col} from 'react-bootstrap'; import AddPlant from './AddPlant' import Plants from './Plants' import ActivatePlant from './ActivatePlant' import {getAllPlantTypes} from "../api/plantTypes"; class Settings extends React.Component{ constructor(props){ super(props); this.state = { plants: [], types: [], } } componentDidMount() { (async ()=>{ this.setState({ types: getAllPlantTypes(), }) })(); } // pass this function to the addplant comp as a prop addPlant = (plant) => { plant.id = this.state.plants.length + 1 // TODO rework let plants = [...this.state.plants, plant]; // create a copy of the array and add the new plant to it this.setState({ plants: plants }) } deletePlant = (id) => { let plants = this.state.plants.filter(plant =>{ // callback function return plant.id !== id // when it returns false (the id is the same), it filters this object out of the array }) this.setState({ plants: plants }) } activatePlant = (plant) => { console.log('The plant ' + plant.name + ' will be monitored') // TODO head for activate logic } render(){ return ( <>

Settings

Configurate your plant here. Based on your settings the smart garden will automate your plant environment.



); } } export default Settings;