+ Name:
+ {this.nameInput=(input)}}
+ placeholder="plant"
+ onChange={(e)=>this.setState({name:e.target.value})} />
+
+
+ Type:
+ this.setState({type:e.target.value})}
+ >
+
+ {this.props.typeArray.map((type, index) =>{
+ return
+ })}
+
+
+
+
+ >
+ );
+ }
+}
+
+export default AddPlant;
+
diff --git a/imports/ui/Settings.jsx b/imports/ui/Settings.jsx
index e1cad0c..6f298e9 100644
--- a/imports/ui/Settings.jsx
+++ b/imports/ui/Settings.jsx
@@ -1,5 +1,5 @@
import React from 'react'
-
+import AddPlant from './AddPlant'
import { Button, Form, Container, Row, Col, Table } from 'react-bootstrap';
class Settings extends React.Component{
@@ -7,20 +7,20 @@ 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
-
+ // pass this function to the addplant comp as a prop
+ addPlant = (plant) => {
+ plant.id = Math.random(); // rework
+
+ let plants = [...this.state.plants, plant]; // create a copy of the array and add the new plant to it
+
+ this.setState({
+ plants: plants
+ })
}
render(){
@@ -38,50 +38,7 @@ class Settings extends React.Component{
- {
- 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
- }
+
@@ -109,8 +66,6 @@ class Settings extends React.Component{
{plant[0]}
{plant[1]}
{plant[2]}
-
-
})
}
@@ -125,57 +80,6 @@ class Settings extends React.Component{
);
}
- // 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;
From f765ba3f631fb2e63b6c1324bfe737c468968b02 Mon Sep 17 00:00:00 2001
From: Max <ḿax.seyfried@gmx.de>
Date: Mon, 6 Jul 2020 10:54:41 +0200
Subject: [PATCH 02/10] restored submit functionality
---
imports/ui/AddPlant.jsx | 4 ++--
imports/ui/Plants.jsx | 34 ++++++++++++++++++++++++++++++++++
imports/ui/Settings.jsx | 30 +++---------------------------
3 files changed, 39 insertions(+), 29 deletions(-)
create mode 100644 imports/ui/Plants.jsx
diff --git a/imports/ui/AddPlant.jsx b/imports/ui/AddPlant.jsx
index a1961ce..4f5dae4 100644
--- a/imports/ui/AddPlant.jsx
+++ b/imports/ui/AddPlant.jsx
@@ -22,8 +22,8 @@ class AddPlant extends React.Component{
// search for arrow function for further syntax knowledge
handleSubmit = (e) => {
e.preventDefault();
- console.log(this.state)
- //this.props.addPlant
+ //console.log(this.state)
+ this.props.addPlant(this.state)
}
diff --git a/imports/ui/Plants.jsx b/imports/ui/Plants.jsx
new file mode 100644
index 0000000..7d289d9
--- /dev/null
+++ b/imports/ui/Plants.jsx
@@ -0,0 +1,34 @@
+import React from 'react'
+import { Table } from 'react-bootstrap';
+
+const Plants = ({plants}) => {
+
+ return (
+ <>
+ {
+ plants.length !== 0 ?
+
+
+
+
Plant name
+
Plant type
+
+
+
+ {
+ plants.map((plant, index) => {
+ return
+
{plant.name}
+
{plant.type}
+
+ })
+ }
+
+
: null
+ }
+ >
+ );
+
+}
+
+export default Plants
\ No newline at end of file
diff --git a/imports/ui/Settings.jsx b/imports/ui/Settings.jsx
index 6f298e9..ab0a3ae 100644
--- a/imports/ui/Settings.jsx
+++ b/imports/ui/Settings.jsx
@@ -1,5 +1,6 @@
import React from 'react'
import AddPlant from './AddPlant'
+import Plants from './Plants'
import { Button, Form, Container, Row, Col, Table } from 'react-bootstrap';
class Settings extends React.Component{
@@ -14,7 +15,7 @@ class Settings extends React.Component{
// pass this function to the addplant comp as a prop
addPlant = (plant) => {
- plant.id = Math.random(); // rework
+ plant.id = Math.random(); // TODO rework
let plants = [...this.state.plants, plant]; // create a copy of the array and add the new plant to it
@@ -47,32 +48,7 @@ class Settings extends React.Component{
- {
- this.state.plants.length !== 0?
-