{"size": 1032, "ext": "js", "max_stars_repo_path": "app/javascript/redux/reducers/suggestedQuizzes.js", "max_stars_repo_name": "galahq/gala", "max_stars_repo_stars_event_min_datetime": "2017-11-11T15:19:50.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-03T08:57:49.000Z", "max_issues_repo_path": "app/javascript/redux/reducers/suggestedQuizzes.js", "max_issues_repo_name": "galahq/gala", "max_issues_repo_issues_event_min_datetime": "2017-11-02T22:10:48.000Z", "max_issues_repo_issues_event_max_datetime": "2020-01-27T18:13:33.000Z", "max_forks_repo_path": "app/javascript/redux/reducers/suggestedQuizzes.js", "max_forks_repo_name": "galahq/gala", "max_forks_repo_forks_event_min_datetime": "2018-05-09T20:06:08.000Z", "max_forks_repo_forks_event_max_datetime": "2019-10-14T16:39:19.000Z"}
{"max_stars_count": 5, "max_issues_count": 174, "max_forks_count": 2, "avg_line_length": 19.8461538462, "max_line_length": 56, "alphanum_fraction": 0.6598837209}
/**
 * @providesModule suggestedQuizzes
 * @flow
 */

import produce from 'immer'

import type { SuggestedQuizzesState } from 'redux/state'

import type {
  SetSuggestedQuizzesAction,
  AddSuggestedQuizAction,
  UpdateSuggestedQuizAction,
  RemoveSuggestedQuizAction,
} from 'redux/actions'

type Action =
  | SetSuggestedQuizzesAction
  | AddSuggestedQuizAction
  | UpdateSuggestedQuizAction
  | RemoveSuggestedQuizAction

export default function suggestedQuizzes (
  state: SuggestedQuizzesState = {},
  action: Action
) {
  switch (action.type) {
    case 'SET_SUGGESTED_QUIZZES':
      return action.quizzes.reduce((obj, quiz) => {
        obj[quiz.param] = quiz
        return obj
      }, {})

    case 'ADD_SUGGESTED_QUIZ':
    case 'UPDATE_SUGGESTED_QUIZ':
      return {
        ...state,
        [action.param]: action.data,
      }

    case 'REMOVE_SUGGESTED_QUIZ': {
      const { param } = action
      return produce(state, draft => {
        delete draft[param]
      })
    }

    default:
      return state
  }
}
