{"size": 831, "ext": "js", "max_stars_repo_path": "src/reducers/users.js", "max_stars_repo_name": "fhansa/udacity_would_you_rather", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/reducers/users.js", "max_issues_repo_name": "fhansa/udacity_would_you_rather", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/reducers/users.js", "max_forks_repo_name": "fhansa/udacity_would_you_rather", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 23.7428571429, "max_line_length": 85, "alphanum_fraction": 0.5523465704}
import { Actions } from '../actions/users'

export default function users (state = {}, action) {

  switch(action.type) {
    case Actions.GET_USERS :
      return {
        ...state,
        ...action.users
      }
    case Actions.ADD_QUESTION_TO_AUTHOR :
      const author = state[action.author.id];
      author.questions.push(action.questionId);
      return {
        ...state, [action.author.id] : author  
      }
    case Actions.ADD_ANSWER_TO_USER :

      const selectedOption = action.selectedOption === 1 ? "optionOne" : "optionTwo";

      return {
        ...state, 
        [action.userId] : {
          ...state[action.userId],
          answers: {
            ...state[action.userId].answers,
            [action.questionId] : selectedOption
          }
        } 
      }

    default :
      return state
  }
}