Newer
Older
import { AnyAction } from 'redux'
import Types from '../actions/types'
import { RichCompetition } from './../interfaces/ApiRichModels'
interface PresentationState {
competition: RichCompetition
slide: Slide
teams: Team[]
}
const initialState: PresentationState = {
competition: {
name: '',
id: 0,
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
slides: [],
year: 0,
teams: [],
},
slide: {
competition_id: 0,
id: 0,
order: 0,
timer: 0,
title: '',
},
teams: [],
}
export default function (state = initialState, action: AnyAction) {
switch (action.type) {
case Types.SET_PRESENTATION_COMPETITION:
return {
...state,
slide: action.payload.slides[0] as Slide,
competition: action.payload as RichCompetition,
}
case Types.SET_PRESENTATION_TEAMS:
return {
...state,
teams: action.payload as Team[],
}
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
default:
return state
}
}