-
Notifications
You must be signed in to change notification settings - Fork 0
/
reducer.js
83 lines (69 loc) · 1.67 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
83
// ❗ You don't need to add extra reducers to achieve MVP
import { combineReducers } from 'redux';
import {
MOVE_CLOCKWISE,
MOVE_COUNTERCLOCKWISE,
SET_SELECTED_ANSWER,
SET_INFO_MESSAGE,
INPUT_CHANGE,
RESET_FORM,
SET_QUIZ_INTO_STATE,
} from "./action-types";
const initialWheelState = 0
function wheel(state = initialWheelState, action) {
console.log('Action:', action);
switch (action.type) {
case MOVE_CLOCKWISE:
return state === 5 ? 0 : state + 1
case MOVE_COUNTERCLOCKWISE:
return state === 0 ? 5 : state - 1
default:
return state;
}
}
const initialQuizState = null
function quiz(state = initialQuizState, action) {
switch (action.type) {
case SET_QUIZ_INTO_STATE:
return action.payload;
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 SET_INFO_MESSAGE:
return action.payload;
default:
return state;
}
}
const initialFormState = {
newQuestion: '',
newTrueAnswer: '',
newFalseAnswer: '',
}
function form(state = initialFormState, action) {
switch (action.type) {
case INPUT_CHANGE:
return {
...state,
[action.payload.name]: action.payload.value
}
case RESET_FORM:
return initialFormState
default:
return state;
}
};
export default combineReducers({ wheel, quiz, selectedAnswer, infoMessage, form })