import { FETCHING_LISTINGS, GET_ALL_LISTINGS_SUCCESS, CHANGE_SEARCH_FIELD, CHANGE_DISTANCE_RADIUS, CHANGE_FILTER_CATEGORY } from '../constants';


export const initialState = {
  allListings: [],
  isFetching: false,
  searchField: '',
  filters: {
    categories: {
      'Home Improvement': false,
      Technology: false,
    },
    distance: false,
  },
};

export const listings = (state = initialState, action) => {
  switch (action.type) {
    case GET_ALL_LISTINGS_SUCCESS:
      return ({ ...state, allListings: action.payload, isFetching: false });
    case FETCHING_LISTINGS:
      return ({ ...state, isFetching: true });
    case CHANGE_SEARCH_FIELD:
      return ({ ...state, searchField: action.value });
    case CHANGE_FILTER_CATEGORY:
      return ({ ...state, filters: { ...state.filters, categories: {...state.filters.categories, [action.category]: !state.filters.categories[action.category] } } });
    case CHANGE_DISTANCE_RADIUS:
      return ({ ...state, filters: { ...state.filters, distance: action.distance } });
    default:
      return state;
  }
};

@@ -114,16 +114,36 @@
 CATEGORY
+, CHANGE_SORT_FILTER
  %7D from 
@@ -366,16 +366,33 @@
  false,%0A
+    sort: false,%0A
   %7D,%0A%7D;%0A
@@ -1066,24 +1066,132 @@
 tance %7D %7D);%0A
+    case CHANGE_SORT_FILTER:%0A      return (%7B ...state, filters: %7B ...state.filters, sort: action.sort %7D %7D);%0A
     default:

add change sort to listing reducer