Skip to content

Instantly share code, notes, and snippets.

@ghoshabhi
Created June 11, 2017 20:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ghoshabhi/7233e7d5143c4b9d8108c5ebb936d60c to your computer and use it in GitHub Desktop.
Save ghoshabhi/7233e7d5143c4b9d8108c5ebb936d60c to your computer and use it in GitHub Desktop.
import * as types from './constants';
import { find, near } from './utils';
export const initialState = {
selectedFilters: [],
find,
near,
};
const filterListReducer = (state = initialState, action) => {
switch (action.type) {
case types.SET_USER_FILTER: {
const { selectedFilters } = state;
const copySelectedFilters = selectedFilters;
const checked = copySelectedFilters.indexOf(action.payload) !== -1;
if (checked) {
const index = copySelectedFilters.indexOf(action.payload);
selectedFilters.splice(index, 1);
} else {
copySelectedFilters.push(action.payload);
}
return {
...state,
selectedFilters: copySelectedFilters,
};
}
case types.TOGGLE_FIND_FILTER:
return {
...state,
find: action.payload,
};
case types.TOGGLE_NEAR_FILTER:
return {
...state,
near: action.payload,
};
default:
return state;
}
};
export default filterListReducer;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment