Newer
Older
import { AnyAction } from 'redux'
import Types from '../actions/types'
import { RichCompetition } from './../interfaces/ApiRichModels'
/** Define a type for the presentation state */
interface PresentationState {
competition: RichCompetition
slide: Slide
/** Define the initial values for the presentation state */
const initialState: PresentationState = {
competition: {
name: '',
slides: [],
year: 0,
teams: [],
},
slide: {
competition_id: 0,
order: 0,
timer: 0,
title: '',
code: '',
timer: {
enabled: false,
value: 0,
},
/** Intercept actions for presentation state and update the state */
export default function (state = initialState, action: AnyAction) {
switch (action.type) {
case Types.SET_PRESENTATION_COMPETITION:
return {
...state,
competition: action.payload as RichCompetition,
}
case Types.SET_PRESENTATION_CODE:
return {
...state,
code: action.payload,
}
case Types.SET_PRESENTATION_SLIDE:
return {
...state,
slide: action.payload as Slide,
}
case Types.SET_PRESENTATION_SLIDE_PREVIOUS:
if (state.slide.order - 1 >= 0) {
return {
...state,
slide: state.competition.slides[state.slide.order - 1],
}
}
return state
case Types.SET_PRESENTATION_SLIDE_NEXT:
if (state.slide.order + 1 < state.competition.slides.length) {
return {
...state,
slide: state.competition.slides[state.slide.order + 1],
}
}
return state
case Types.SET_PRESENTATION_SLIDE_BY_ORDER:
if (0 <= action.payload && action.payload < state.competition.slides.length)
return {
...state,
slide: state.competition.slides[action.payload],
}
return state
case Types.SET_PRESENTATION_TIMER:
if (action.payload.value == 0) {
action.payload.enabled = false
}
return {
...state,
timer: action.payload,
}
default:
return state
}
}