Proyectos de Subversion LeadersLinked - SPA

Rev

Ir a la última revisión | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |

import { QUIZ_ACTIONS } from './quiz.types'

const initialState = {
  status: 'default',
  questions: [],
  answers: [],
  score: 0,
  currentQuestion: 0,
  isFinished: false
}

const quizReducer = (state = initialState, { type, payload }) => {
  switch (type) {
    case QUIZ_ACTIONS.SET_QUESTIONS: {
      return { ...state, questions: payload }
    }
    case QUIZ_ACTIONS.SET_STATUS: {
      return { ...state, status: payload }
    }
    case QUIZ_ACTIONS.SET_ANSWER: {
      return { ...state, answers: [...state.answers, payload] }
    }
    default:
      return state
  }
}

export default quizReducer