{"size": 1006, "ext": "js", "max_stars_repo_path": "app/containers/DaywiseCalorieIntakeListContainer/reducer.js", "max_stars_repo_name": "clydemendonca/mealtracker-web", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "app/containers/DaywiseCalorieIntakeListContainer/reducer.js", "max_issues_repo_name": "clydemendonca/mealtracker-web", "max_issues_repo_issues_event_min_datetime": "2020-07-20T12:01:57.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-26T14:39:31.000Z", "max_forks_repo_path": "app/containers/DaywiseCalorieIntakeListContainer/reducer.js", "max_forks_repo_name": "clydemendonca/mealtracker-web", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 3, "max_forks_count": null, "avg_line_length": 23.3953488372, "max_line_length": 86, "alphanum_fraction": 0.662027833}
/*
 *
 * DaywiseCalorieIntakeListContainer reducer
 *
 */
import produce from 'immer';
import { DEFAULT_ACTION, FETCH_DAYWISE_CALORIE_INTAKE_SUCCESSFUL } from './constants';

export const initialState = {
  daywiseCalorieIntakeForUser: []
};

/* eslint-disable default-case, no-param-reassign */
const daywiseCalorieIntakeListContainerReducer = (
  state = initialState,
  action,
) =>
  produce(state, (/* draft */) => {
    switch (action.type) {
      case DEFAULT_ACTION:
        break;


      case FETCH_DAYWISE_CALORIE_INTAKE_SUCCESSFUL:
        const { dailyCalorieIntake, calorieIntakeForUser } = action.payload;

        const daywiseCalorieIntakeForUser = calorieIntakeForUser.map((item) => {
          return {
            ...item,
            isTotalLessThanDailyCalorieIntake: item.total <= dailyCalorieIntake
          }
        });

        return {
          ...state,
          daywiseCalorieIntakeForUser,
        }

    }
  });

export default daywiseCalorieIntakeListContainerReducer;
