{"size": 2044, "ext": "js", "max_stars_repo_path": "client/reducers/history.js", "max_stars_repo_name": "torkpe/HelloBooks", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "client/reducers/history.js", "max_issues_repo_name": "torkpe/HelloBooks", "max_issues_repo_issues_event_min_datetime": "2017-12-08T17:55:34.000Z", "max_issues_repo_issues_event_max_datetime": "2018-01-30T12:32:50.000Z", "max_forks_repo_path": "client/reducers/history.js", "max_forks_repo_name": "torkpe/HelloBooks", "max_forks_repo_forks_event_min_datetime": "2018-02-16T08:24:46.000Z", "max_forks_repo_forks_event_max_datetime": "2018-02-16T08:24:46.000Z"}
{"max_stars_count": null, "max_issues_count": 83, "max_forks_count": 1, "avg_line_length": 20.0392156863, "max_line_length": 74, "alphanum_fraction": 0.5831702544}
import types from '../types/types';

const {
  GET_ALL_BORROWED_BOOKS,
  GET_BORROWED_BOOKS_SUCCESSFUL,
  FAILED_TO_GET_BORROWED_BOOKS,
  GET_NOT_RETURNED_BOOKS,
  GET_NOT_RETURNED_SUCCESSFUL,
  FAILED_TO_GET_NOT_RETURNED_BOOKS,
  CLEAR_BOOKS_STATE
} = types;

const initialState = {
  isLoading: false,
  errors: {},
};
/**
 * @description Get all borrowed function for state
 * 
 * @param {object} state
 * @param {object} action
 * 
 * @returns {object} state
 */
export const getAllBorrowed = (state = initialState, action = {}) => {
  switch (action.type) {
    case GET_ALL_BORROWED_BOOKS: {
      return {
        ...state,
        isLoading: true,
      };
    }
    case GET_BORROWED_BOOKS_SUCCESSFUL: {
      return {
        ...state,
        isLoading: false,
        borrowedBooks: action.payload,
      };
    }
    case FAILED_TO_GET_BORROWED_BOOKS: {
      return {
        ...state,
        isLoading: false,
        errors: action.payload,
      };
    }
    case CLEAR_BOOKS_STATE: {
      return {
        ...state,
        isLoading: false,
        borrowedBooks: [],
      };
    }
    default: return state;
  }
};
const notReturnedState = {
  isLoading: false,
  notReturned: [],
  errors: {},
};
/**
 * @description Get all not returned function for state
 * 
 * @param {object} state
 * @param {object} action
 * 
 * @returns {object} state
 */
export const allNotReturned = (state = notReturnedState, action = {}) => {
  switch (action.type) {
    case GET_NOT_RETURNED_BOOKS: {
      return {
        ...state,
        isLoading: true,
      };
    }
    case GET_NOT_RETURNED_SUCCESSFUL: {
      return {
        ...state,
        isLoading: false,
        notReturned: action.payload,
      };
    }
    case FAILED_TO_GET_NOT_RETURNED_BOOKS: {
      return {
        ...state,
        isLoading: false,
        errors: action.payload,
      };
    }
    case CLEAR_BOOKS_STATE: {
      return {
        ...state,
        isLoading: false,
        notReturned: [],
      };
    }
    default: return state;
  }
};
