import * as types from './constants';
import update from 'react-addons-update';

export const initialState = {
  isLoading: false,
  carouselImages: [],
  featuredArticles: null,
  error: null,
};

const landingReducer =
  (state = initialState, action) => {
    switch (action.type) {
      case types.FEATURED_ARTICLES_INITIATION:
        return update(state, {
          isLoading: {
            $set: true,
          },
        });
      case types.FEATURED_ARTICLES_SUCCESS:
        return update(state, {
          isLoading: {
            $set: false,
          },
          featuredArticles: {
            $set: action.articles,
          },
        });
      case types.FEATURE_ARTICLES_FAILURE:
        return update(state, {
          isLoading: {
            $set: false,
          },
          error: {
            $set: action.error,
          },
        });
      case types.CLEAR_LANDING_ERROR:
        return update(state, {
          error: {
            $set: null,
          },
        });
      case types.SPOTLIGHTED_IMAGES_INITIATION:
        return update(state, {
          isLoading: {
            $set: true,
          },
        });
      case types.SPOTLIGHTED_IMAGES_SUCCESS:
        return update(state, {
          carouselImages: {
            $set: action.images,
          },
        });
      case types.SPOTLIGHTED_IMAGES_FAILURE:
        return update(state, {
          error: {
            $set: action.error,
          },
        });
      default:
        return state;
    }
  };

export default landingReducer;

@@ -1296,32 +1296,93 @@
 s,%0A          %7D,%0A
+          isLoading: %7B%0A            $set: false,%0A          %7D,%0A
         %7D);%0A    
@@ -1509,32 +1509,93 @@
 r,%0A          %7D,%0A
+          isLoading: %7B%0A            $set: false,%0A          %7D,%0A
         %7D);%0A    

add isLoading false in landing container spotlight image reducer