@@ -83,15 +83,17 @@ export const setWines = (region, wines) => {
83
83
} ;
84
84
}
85
85
86
- export const loading = ( ) => {
86
+ export const loading = ( what ) => {
87
87
return {
88
- type : 'LOADING'
88
+ type : 'LOADING' ,
89
+ what
89
90
} ;
90
91
}
91
92
92
- export const loaded = ( ) => {
93
+ export const loaded = ( what ) => {
93
94
return {
94
- type : 'LOADED'
95
+ type : 'LOADED' ,
96
+ what
95
97
} ;
96
98
}
97
99
@@ -117,25 +119,25 @@ export const updateWinesTimestamp = (region) => {
117
119
118
120
export function fetchLikesCount ( ) {
119
121
return dispatch => {
120
- dispatch ( loading ( ) ) ;
122
+ dispatch ( loading ( 'Likes count' ) ) ;
121
123
fetch ( `/api/likes` )
122
124
. then ( r => r . json ( ) )
123
125
. then ( r => {
124
126
dispatch ( setLikes ( r . count ) ) ;
125
- dispatch ( loading ( ) ) ;
127
+ dispatch ( loaded ( 'Likes count' ) ) ;
126
128
} )
127
129
. catch ( error => dispatch ( errorLoading ( `error while fetching like count : ${ error . message } ` ) ) ) ;
128
130
} ;
129
131
}
130
132
131
133
export function fetchCommentsCount ( ) {
132
134
return dispatch => {
133
- dispatch ( loading ( ) ) ;
135
+ dispatch ( loading ( 'Comment counts' ) ) ;
134
136
fetch ( `/api/comments` )
135
137
. then ( r => r . json ( ) )
136
138
. then ( r => {
137
139
dispatch ( setComments ( r . count ) ) ;
138
- dispatch ( loaded ( ) ) ;
140
+ dispatch ( loaded ( 'Comment counts' ) ) ;
139
141
} )
140
142
. catch ( error => dispatch ( errorLoading ( `error while fetching comment count : ${ error . message } ` ) ) ) ;
141
143
} ;
@@ -144,13 +146,13 @@ export function fetchCommentsCount() {
144
146
export function fetchRegions ( ) {
145
147
return ( dispatch , state ) => {
146
148
if ( state ( ) . regions . lastUpdated + 60000 < Date . now ( ) ) {
147
- dispatch ( loading ( ) ) ;
149
+ dispatch ( loading ( 'Regions' ) ) ;
148
150
fetch ( '/api/regions' )
149
151
. then ( r => r . json ( ) )
150
152
. then ( data => {
151
153
dispatch ( updateRegionsTimestamp ( ) ) ;
152
154
dispatch ( setRegions ( data ) ) ;
153
- dispatch ( loaded ( ) ) ;
155
+ dispatch ( loaded ( 'Regions' ) ) ;
154
156
} )
155
157
. catch ( error => dispatch ( errorLoading ( `error while fetching regions : ${ error . message } ` ) ) ) ;
156
158
} else {
@@ -164,13 +166,13 @@ export function fetchWinesForRegion(regionId) {
164
166
const lastUpdated = ( state ( ) . wines [ regionId ] || { lastUpdated : 0 } ) . lastUpdated ;
165
167
if ( lastUpdated + 60000 < Date . now ( ) ) {
166
168
dispatch ( setCurrentRegion ( regionId ) ) ;
167
- dispatch ( loading ( ) ) ;
169
+ dispatch ( loading ( `Wines for region ${ regionId } ` ) ) ;
168
170
fetch ( `/api/wines?region=${ regionId } ` )
169
171
. then ( r => r . json ( ) )
170
172
. then ( data => {
171
173
dispatch ( updateWinesTimestamp ( regionId ) ) ;
172
174
dispatch ( setWines ( regionId , data ) ) ;
173
- dispatch ( loaded ( ) ) ;
175
+ dispatch ( loaded ( `Wines for region ${ regionId } ` ) ) ;
174
176
} )
175
177
. catch ( error => dispatch ( errorLoading ( `error while fetching wines for ${ regionId } : ${ error . message } ` ) ) ) ;
176
178
} else {
@@ -181,12 +183,12 @@ export function fetchWinesForRegion(regionId) {
181
183
182
184
export function fetchWine ( wineId ) {
183
185
return dispatch => {
184
- dispatch ( loading ( ) ) ;
186
+ dispatch ( loading ( `wine with id ${ wineId } ` ) ) ;
185
187
return fetch ( `/api/wines/${ wineId } ` )
186
188
. then ( r => r . json ( ) )
187
189
. then ( data => {
188
190
dispatch ( setCurrentWine ( data ) ) ;
189
- dispatch ( loaded ( ) ) ;
191
+ dispatch ( loaded ( `wine with id ${ wineId } ` ) ) ;
190
192
} )
191
193
. catch ( error => dispatch ( errorLoading ( `error while fetching wine ${ wineId } : ${ error . message } ` ) ) ) ;
192
194
} ;
0 commit comments