Created
August 10, 2018 05:48
-
-
Save maximgatilin/f1c0cac4054b069d7fb0f6c78e2f21af 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 { | |
CHANGE_USERS_AGE_FILTER, | |
} from '../actions/actionTypes'; | |
import users from '../../mockData/users'; | |
import {getMaxVal, getMinVal, getValueFromUrl} from '../../utils/functions'; | |
const minAge = getMinVal(users, 'age'); | |
const maxAge = getMaxVal(users, 'age'); | |
const minAgeFilter = getValueFromUrl('users.minAge'); | |
const maxAgeFilter = getValueFromUrl('users.maxAge'); | |
const initialState = { | |
list: users, | |
minAge, | |
maxAge, | |
minAgeFilter: minAgeFilter === null ? minAge : Number(minAgeFilter), | |
maxAgeFilter: maxAgeFilter === null ? maxAge : Number(maxAgeFilter), | |
}; | |
export default (state = initialState, action) => { | |
switch (action.type) { | |
case CHANGE_USERS_AGE_FILTER: | |
return { | |
...state, | |
minAgeFilter: action.payload.filter[0], | |
maxAgeFilter: action.payload.filter[1], | |
}; | |
default: | |
return state; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment