From 310418be7b86c115e36caff7c9390d6745390481 Mon Sep 17 00:00:00 2001 From: Max <ḿax.seyfried@gmx.de> Date: Mon, 6 Jul 2020 11:10:17 +0200 Subject: [PATCH] restored delete functionality --- imports/ui/Plants.jsx | 6 ++++-- imports/ui/Settings.jsx | 19 +++++++++++++++++-- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/imports/ui/Plants.jsx b/imports/ui/Plants.jsx index 7d289d9..51f8870 100644 --- a/imports/ui/Plants.jsx +++ b/imports/ui/Plants.jsx @@ -1,7 +1,7 @@ import React from 'react' -import { Table } from 'react-bootstrap'; +import { Table, Button } from 'react-bootstrap'; -const Plants = ({plants}) => { +const Plants = ({plants, deletePlant}) => { return ( <> @@ -12,6 +12,7 @@ const Plants = ({plants}) => { Plant name Plant type + @@ -20,6 +21,7 @@ const Plants = ({plants}) => { return {plant.name} {plant.type} + }) } diff --git a/imports/ui/Settings.jsx b/imports/ui/Settings.jsx index ab0a3ae..b9b130f 100644 --- a/imports/ui/Settings.jsx +++ b/imports/ui/Settings.jsx @@ -24,6 +24,15 @@ class Settings extends React.Component{ }) } + 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 + }) + } + render(){ return ( <> @@ -39,7 +48,10 @@ class Settings extends React.Component{

- + @@ -48,7 +60,10 @@ class Settings extends React.Component{

- +