From 50eaaa9dfaa2d4aa1230e7a6b371a60c1df8a1ab Mon Sep 17 00:00:00 2001
From: Jules Laplace <jules@okfoc.us>
Date: Mon, 20 Mar 2017 03:51:23 +0100
Subject: group by date

---
 client/components/MealFilter.jsx | 17 ++++++-----------
 1 file changed, 6 insertions(+), 11 deletions(-)

(limited to 'client/components/MealFilter.jsx')

diff --git a/client/components/MealFilter.jsx b/client/components/MealFilter.jsx
index e9dfbd8..e326b4b 100644
--- a/client/components/MealFilter.jsx
+++ b/client/components/MealFilter.jsx
@@ -36,7 +36,6 @@ export default class MealFilter extends React.Component {
     state = state || this.state
     let start = state.startDate
     let end = state.endDate
-    console.log(start.toDate(), end.toDate())
 
     client.service('meals').find({
       query: {
@@ -46,17 +45,17 @@ export default class MealFilter extends React.Component {
         token: client.get('token'),
       },
     }).then((data) => {
-      console.log(data)
       this.setState({meals: data.data})
       this.filter(data.data)
     }).catch((error) => {
       console.error(error)
     })
   }
-  filter(meals) {
+  filter(meals, state) {
     meals = meals || this.state.meals
-    const start = this.state.startTime
-    const end = this.state.endTime
+    state = state || this.state
+    const start = state.startTime
+    const end = state.endTime
     const filteredMeals = this.state.meals.filter((meal) => {
       const hours = new Date(meal.date).getHours()
       return (start <= hours && hours <= end)
@@ -69,11 +68,7 @@ export default class MealFilter extends React.Component {
     start.minutes(0)
     start.seconds(0)
 
-    let end = range.endDate
-    if (start.isSame(end)) {
-      end = start.clone()
-    }
-
+    const end = start.isSame(range.endDate) ? start.clone() : range.endDate
     end.hours(23)
     end.minutes(59)
     end.seconds(59)
@@ -89,7 +84,7 @@ export default class MealFilter extends React.Component {
   }
   pickTimeRange(event,start,end){
     this.setState({startTime: start, endTime: end})
-    this.filter()
+    this.filter(this.state.meals, {startTime: start, endTime: end})
   }
 
   render(){
-- 
cgit v1.2.3-70-g09d2

