-
Notifications
You must be signed in to change notification settings - Fork 0
/
VeggieListComponent.js
117 lines (103 loc) · 4.02 KB
/
VeggieListComponent.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import React, { Component } from 'react';
import { Link } from 'react-router-dom';
import VeggieServices from '../../services/VeggieServices';
import './Lists.css';
class VeggieListComponent extends Component {
constructor(props) {
super(props)
this.state = {
veggies: []
}
this.addVeggie = this.addVeggie.bind(this);
this.editVeggie = this.editVeggie.bind(this);
this.deleteVeggie = this.deleteVeggie.bind(this);
}
addVeggie(id) {
//this.props.history.push("/pantry");
VeggieServices.addVeggieToPantry(id, this.props.loggedInUser.id ).then( res => {
console.log("Update pantry ::> ", res.data)
this.props.updatePantry(res.data)
this.props.history.push("/pantry");
});
}
editVeggie(id) {
// this.props.history.push(`/update-veggie/${id}`);
}
deleteVeggie(id) {
VeggieServices.deleteVeggie(id).then( res => {
this.setState({ veggies: this.state.veggies.filter(veggie => veggie.id !== id)});
});
}
/* addVeggie = (e) => {
e.preventDefault();
let veggie = {name: this.state.name};
console.log('veggie =>' + JSON.stringify(veggie));
VeggieServices.getVeggieById(veggie)
.then(res => {
this.props.history.push('/pantry');
}).catch(err => {
console.log(err)
})
} */
componentDidMount() {
VeggieServices.getVeggies().then((res) => {
this.setState({veggies: res.data});
});
}
render() {
return (
<div>
<div className="sidenav">
<Link to="/pantry">Home</Link>
<Link to="/fruits">Fruits</Link>
<Link to="/veggies">Veggies</Link>
<Link to="/coming-soon">Coming Soon</Link>
<button style={{marginLeft: "35px", marginTop: "50px"}} type="button" class="btn btn-outline-light"onClick={(e) => this.Signout(e)}>Log Out</button>
</div>
<body id="veggie-list">
<div className= "container">
<h2 className="text-center">Veggie List</h2>
<div className="row">
</div>
<table className ="table table-striped bordered hover variant= dark">
<thead>
<tr>
<th>Image</th>
<th>Name</th>
<th>Clean</th>
<th>Storage</th>
<th>Fresh Time</th>
<th>Fresh Prep</th>
<th>Freeze Time</th>
<th>Freeze Prep</th>
<th>Add to Pantry</th>
</tr>
</thead>
<tbody>
{
this.state.veggies.map(
veggie =>
<tr key = {veggie.id}>
<td>{veggie.image}</td>
<td>{veggie.name}</td>
<td>{veggie.clean}</td>
<td>{veggie.storage}</td>
<td>{veggie.freshTime}</td>
<td>{veggie.freshPrep}</td>
<td>{veggie.freezeTime}</td>
<td>{veggie.freezePrep}</td>
<td>
<button className="btn btn-outline-success" onClick={() => this.addVeggie(veggie.id)}>Add</button>
</td>
</tr>
)
}
</tbody>
</table>
</div>
</body>
</div>
);
}
}
export default VeggieListComponent;