Newer
Older
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
84
85
86
87
88
import {
get as apiGet,
create,
remove,
update,
} from 'pubsweet-client/src/helpers/api'
const REQUEST = 'recommendations/REQUEST'
const ERROR = 'recommendations/ERROR'
const GET_RECOMMENDATIONS_SUCCESS = 'recommendations/GET_SUCCESS'
const GET_RECOMMENDATION_SUCCESS = 'recommendations/GET_ITEM_SUCCESS'
const UPDATE_RECOMMENDATION_SUCCESS = 'recommendations/UPDATE_SUCCESS'
export const recommendationsRequest = () => ({
type: REQUEST,
})
export const recommendationsError = error => ({
type: ERROR,
error,
})
export const getRecommendationsSuccess = recommendations => ({
type: GET_RECOMMENDATIONS_SUCCESS,
payload: { recommendations },
})
export const getRecommendationSuccess = recommendation => ({
type: GET_RECOMMENDATION_SUCCESS,
payload: { recommendation },
})
export const updateRecommendationSuccess = recommendation => ({
type: UPDATE_RECOMMENDATION_SUCCESS,
payload: { recommendation },
})
// Actions
// State
const initialState = {
fetching: false,
error: null,
recommendations: [],
recommendation: {},
}
export default (state = initialState, action = {}) => {
switch (action.type) {
case REQUEST:
return {
...state,
fetching: true,
recommendations: [],
recommendation: {},
}
case ERROR:
return {
...state,
fetching: false,
error: action.error,
}
case GET_RECOMMENDATIONS_SUCCESS:
return {
...state,
fetching: false,
error: null,
recommendations: action.payload.recommendations,
}
case GET_RECOMMENDATION_SUCCESS:
return {
...state,
fetching: false,
error: null,
recommendation: action.payload.recommendation,
}
case UPDATE_RECOMMENDATION_SUCCESS:
return {
...state,
fetching: false,
error: null,
recommendation: action.payload.recommendation,
}
default:
return state
}
}