Skip to content

Instantly share code, notes, and snippets.

@maximgatilin
Created August 10, 2018 05:48
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 maximgatilin/f1c0cac4054b069d7fb0f6c78e2f21af to your computer and use it in GitHub Desktop.
Save maximgatilin/f1c0cac4054b069d7fb0f6c78e2f21af to your computer and use it in GitHub Desktop.
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