import React from 'react' import { Button, Form, Container, Row, Col, Table } from 'react-bootstrap'; class Settings extends React.Component{ constructor(props){ super(props); this.state = { name: '', type: '', dirt: '', plants: [], types: ['Chile', 'Mint'], // hardcoded for now dirts: ['Vegetable Soil', 'Potting Soil'], // hardcoded for now updateId: -1, btnName: 'submit' } } componentDidMount(){ // fetch data from db here } render(){ return ( <>

Settings

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

{ this.state.updateId >= 0 | this.state.plants.length === 0? // show the form only if we edit the plant or there is no plant set yet
Name {this.nameInput=(input)}} placeholder="plant" onChange={(e)=>this.setState({name:e.target.value})} /> Type this.setState({type:e.target.value})} > {this.state.types.map((type, index) => { return })} Dirt this.setState({dirt:e.target.value})} > {this.state.dirts.map((dirt, index) => { return })}
:null }

{ this.state.plants.length !== 0? { this.state.plants.map((plant, index) => { return }) }
Plant name Plant type Dirt type
{plant[0]} {plant[1]} {plant[2]}
: null }
); } // search for arrow function for further syntax knowledge handleSubmit = (e) => { e.preventDefault(); if (this.state.updateId >= 0) { // check if it is in edit mode this.state.plants[this.state.updateId][0] = this.state.name; this.state.plants[this.state.updateId][1] = this.state.type; this.state.plants[this.state.updateId][2] = this.state.dirt; // updates the name of the plant this.setState({ updateId:-1, // Todo check docu name:'', // reset inputtext again btnName:'submit' // reset button to submit again }) } else { let newDataElement = [ this.state.name, this.state.type, this.state.dirt ] console.log("name " + newDataElement[0]) console.log("type " + newDataElement[1]) console.log("dirt " + newDataElement[2]) this.setState(prevState =>({ plants:[...prevState.plants, newDataElement], // adds a new plant array name:'' //to reset the inputfield })) return this.state.plants; } } removeItem = (value) => { this.setState({ plants:this.state.plants.filter((plant) => { // filter function add docu return plant !== value; }), name:'' }) } editItem = (editedName, editedType, editedDirt, index) => { this.setState({ name:editedName, type:editedType, dirt:editedDirt, btnName:'update', updateId:index // should be edited to a boolean }) } } export default Settings;