diff options
| author | Jules Laplace <jules@okfoc.us> | 2017-03-20 03:51:23 +0100 |
|---|---|---|
| committer | Jules Laplace <jules@okfoc.us> | 2017-03-20 03:51:23 +0100 |
| commit | 50eaaa9dfaa2d4aa1230e7a6b371a60c1df8a1ab (patch) | |
| tree | bc4363ce1055df679116e89dec5beae14e7582b7 /client/components/MealFilter.jsx | |
| parent | d9d81925299aa787cbdb815cb4b06e17a412b40c (diff) | |
group by date
Diffstat (limited to 'client/components/MealFilter.jsx')
| -rw-r--r-- | client/components/MealFilter.jsx | 17 |
1 files changed, 6 insertions, 11 deletions
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(){ |
