Created
June 11, 2017 20:53
-
-
Save ghoshabhi/7233e7d5143c4b9d8108c5ebb936d60c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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