Skip to content

Commit e08180c

Browse files
Better dev experience with devtools
1 parent b4b2b36 commit e08180c

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

step-7/src/actions/index.js

+16-14
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,17 @@ export const setWines = (region, wines) => {
8383
};
8484
}
8585

86-
export const loading = () => {
86+
export const loading = (what) => {
8787
return {
88-
type: 'LOADING'
88+
type: 'LOADING',
89+
what
8990
};
9091
}
9192

92-
export const loaded = () => {
93+
export const loaded = (what) => {
9394
return {
94-
type: 'LOADED'
95+
type: 'LOADED',
96+
what
9597
};
9698
}
9799

@@ -117,25 +119,25 @@ export const updateWinesTimestamp = (region) => {
117119

118120
export function fetchLikesCount() {
119121
return dispatch => {
120-
dispatch(loading());
122+
dispatch(loading('Likes count'));
121123
fetch(`/api/likes`)
122124
.then(r => r.json())
123125
.then(r => {
124126
dispatch(setLikes(r.count));
125-
dispatch(loading());
127+
dispatch(loaded('Likes count'));
126128
})
127129
.catch(error => dispatch(errorLoading(`error while fetching like count : ${error.message}`)));
128130
};
129131
}
130132

131133
export function fetchCommentsCount() {
132134
return dispatch => {
133-
dispatch(loading());
135+
dispatch(loading('Comment counts'));
134136
fetch(`/api/comments`)
135137
.then(r => r.json())
136138
.then(r => {
137139
dispatch(setComments(r.count));
138-
dispatch(loaded());
140+
dispatch(loaded('Comment counts'));
139141
})
140142
.catch(error => dispatch(errorLoading(`error while fetching comment count : ${error.message}`)));
141143
};
@@ -144,13 +146,13 @@ export function fetchCommentsCount() {
144146
export function fetchRegions() {
145147
return (dispatch, state) => {
146148
if (state().regions.lastUpdated + 60000 < Date.now()) {
147-
dispatch(loading());
149+
dispatch(loading('Regions'));
148150
fetch('/api/regions')
149151
.then(r => r.json())
150152
.then(data => {
151153
dispatch(updateRegionsTimestamp());
152154
dispatch(setRegions(data));
153-
dispatch(loaded());
155+
dispatch(loaded('Regions'));
154156
})
155157
.catch(error => dispatch(errorLoading(`error while fetching regions : ${error.message}`)));
156158
} else {
@@ -164,13 +166,13 @@ export function fetchWinesForRegion(regionId) {
164166
const lastUpdated = (state().wines[regionId] || { lastUpdated: 0 }).lastUpdated;
165167
if (lastUpdated + 60000 < Date.now()) {
166168
dispatch(setCurrentRegion(regionId));
167-
dispatch(loading());
169+
dispatch(loading(`Wines for region ${regionId}`));
168170
fetch(`/api/wines?region=${regionId}`)
169171
.then(r => r.json())
170172
.then(data => {
171173
dispatch(updateWinesTimestamp(regionId));
172174
dispatch(setWines(regionId, data));
173-
dispatch(loaded());
175+
dispatch(loaded(`Wines for region ${regionId}`));
174176
})
175177
.catch(error => dispatch(errorLoading(`error while fetching wines for ${regionId} : ${error.message}`)));
176178
} else {
@@ -181,12 +183,12 @@ export function fetchWinesForRegion(regionId) {
181183

182184
export function fetchWine(wineId) {
183185
return dispatch => {
184-
dispatch(loading());
186+
dispatch(loading(`wine with id ${wineId}`));
185187
return fetch(`/api/wines/${wineId}`)
186188
.then(r => r.json())
187189
.then(data => {
188190
dispatch(setCurrentWine(data));
189-
dispatch(loaded());
191+
dispatch(loaded(`wine with id ${wineId}`));
190192
})
191193
.catch(error => dispatch(errorLoading(`error while fetching wine ${wineId} : ${error.message}`)));
192194
};

0 commit comments

Comments
 (0)