@@ -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}