-
Notifications
You must be signed in to change notification settings - Fork 0
/
reducer.js
82 lines (71 loc) · 1.92 KB
/
reducer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// ❗ You don't need to add extra reducers to achieve MVP
import { combineReducers } from 'redux'
import * as types from './action-types.js'
const initialWheelState = {
position: 0 // Initial position of the wheel
};
function wheel(state = initialWheelState, action) {
switch (action.type) {
case 'MOVE_CLOCKWISE':
return {
...state,
position: (state.position + 1) % 6 // Assuming there are 6 cogs
};
case 'MOVE_COUNTERCLOCKWISE':
return {
...state,
position: (state.position + 5) % 6 // Assuming there are 6 cogs
};
default:
return state;
}
}
const initialQuizState = null;
function quiz(state = initialQuizState, action) {
switch (action.type) {
case types.SET_QUIZ_INTO_STATE:
return action.payload; // return fetched quiz data
case 'POST_ANSWER':
return state; // return the existing state
case 'POST_QUIZ':
return state; // return the existing state
default:
return state;
}
}
const initialSelectedAnswerState = null
function selectedAnswer(state = initialSelectedAnswerState, action) {
switch(action.type){
case 'SET_SELECTED_ANSWER':
return action.payload;
default:
return state;
}
}
const initialMessageState = ''
function infoMessage(state = initialMessageState, action) {
switch (action.type) {
case types.SET_INFO_MESSAGE:
return action.payload
case types.SET_SELECTED_ANSWER:
return ''
default:
return state
}
}
const initialFormState = {
newQuestion: '',
newTrueAnswer: '',
newFalseAnswer: '',
}
function form(state = initialFormState, action) {
switch (action.type) {
case types.RESET_FORM:
return initialFormState
case types.INPUT_CHANGE:
return { ...state, [action.payload.inputId]: action.payload.value }
default:
return state
}
}
export default combineReducers({ wheel, quiz, selectedAnswer, infoMessage, form })