xonecas.io
3517
Mt

meal_tracker / commit cda1fef

Add logic to change color of each row

Looking at the user daily limit color code each meal.

xonecas2020-03-06 cda1fefe48eb688ab1e9a716aa05c523655ae2d2 parent 82894e0

2 files changed

bmi_ui/src/components/MealsTable.js+19−4
@@ -21,6 +21,21 @@ class MealsTable extends Component {
2121 };
2222
2323 render() {
24+ var mealsGroupedByDay = {};
25+
26+ this.props.meals.forEach((m, i) => {
27+ mealsGroupedByDay[m.date] = mealsGroupedByDay[m.date] || 0;
28+ mealsGroupedByDay[m.date] += m.calories;
29+ });
30+
31+ this.props.meals.forEach((m) => {
32+ if (mealsGroupedByDay[m.date] > this.props.user.preferences.max_calories) {
33+ m.color = 'pt-3 text-danger';
34+ } else {
35+ m.color = 'pt-3 text-success';
36+ }
37+ });
38+
2439 return (
2540 <Table>
2641 <thead>
@@ -37,10 +52,10 @@ class MealsTable extends Component {
3752 {this.props.meals.map((m, i) =>
3853 <tr key={i}>
3954 <th scope="row" className="pt-3">{i + 1}</th>
40- <th className="pt-3">{m.text}</th>
41- <th className="pt-3">{m.calories}</th>
42- <th className="pt-3">{m.date}</th>
43- <th className="pt-3">{m.time}</th>
55+ <th className={m.color}>{m.text}</th>
56+ <th className={m.color}>{m.calories}</th>
57+ <th className={m.color}>{m.date}</th>
58+ <th className={m.color}>{m.time}</th>
4459 <th>
4560 <MealModal
4661 meal={m}
db.sqlite3+0−0
Binary file, not shown.