text: 
  // import our actions
  import {
    UPDATE_PRODUCTS,
    UPDATE_CATEGORIES,
    UPDATE_CURRENT_CATEGORY,
    ADD_TO_CART,
    ADD_MULTIPLE_TO_CART,
    REMOVE_FROM_CART,
    UPDATE_CART_QUANTITY,
    CLEAR_CART,
    TOGGLE_CART,
  } from './actions';
  
  const initialState = {
    products: [],
    categories: [],
    currentCategory: '',
    cart: [],
    cartOpen: false
  };
  
  export const reducers = (state = initialState, action) => {
    switch (action.type) {
      // if action type value is the value of 'UPDATE_PRODUCTS', return a new state object with an updated products array
      case UPDATE_PRODUCTS:
        return {
          ...state,
          products: [...action.products],
        };
      // if action type value is the value of 'UPDATE_CATEGORIES', return a new state object with an updated categories array
      case UPDATE_CATEGORIES:
        return {
          ...state,
          categories: [...action.categories],
        };
      // if action type value is the value of 'UPDATE_CURRENT_CATEGORY', return a new state object with an updated string indicating the current category
      case UPDATE_CURRENT_CATEGORY:
        return {
          ...state,
          currentCategory: action.currentCategory,
        };
      // if action type value is 'ADD_TO_CART', return a new state object with an updated cart property and cart open
      case ADD_TO_CART:
        return {
          ...state,
          cartOpen: true,
          cart: [...state.cart, action.product],
        };
      // if action type value is 'ADD_MULTIPLE_TO_CART', return a new state object with an updated cart property
      case ADD_MULTIPLE_TO_CART:
        return {
          ...state,
          cart: [...state.cart, ...action.products],
        };
      // if action type value is 'REMOVE_FROM_CART', return a new state object with an updated cart property and cart open or close depending on whether there are products in it
      case REMOVE_FROM_CART:
        let newState = state.cart.filter((product) => {
          return product._id !== action._id;
        });
        return {
          ...state,
          cartOpen: newState.length > 0,
          cart: newState,
        };
      // if action type value is 'UPDATE_CART_QUANTITY', return a new state object with a cart property properly updated for quantity
      case UPDATE_CART_QUANTITY:
        return {
          ...state,
          cartOpen: true,
          cart: state.cart.map((product) => {
            if (action._id === product._id) {
              product.purchaseQuantity = action.purchaseQuantity;
            }
            return product;
          }),
        };
      // if action type value is 'CLEAR_CART', return a new state object with empty (and closed) cart
      case CLEAR_CART:
        return {
          ...state,
          cartOpen: false,
          cart: [],
        };
      // if action type value is 'TOGGLE_CART', return a new state object with cartOpen property opposite its previous value
      case TOGGLE_CART:
        return {
          ...state,
          cartOpen: !state.cartOpen,
        };
      // if it's none of these actions, do not update state at all and keep things the same!
      default:
        return state;
    }
  };
  
  export default reducers;
  