error and loading

This commit is contained in:
2024-04-30 07:38:59 -04:00
parent 2c1d6a9578
commit 78b9432722
8 changed files with 261 additions and 63 deletions

View File

@ -1,11 +1,24 @@
export const STORE_RESTAURANTS = 'STORE_RESTAURANTS';
export const START_LOADING = 'START_LOADING';
export const RECORD_LOADING_ERROR = 'RECORD_LOADING_ERROR';
export const loadRestaurants = () => async (dispatch, getState, api) => {
const records = await api.loadRestaurants();
dispatch(storeRestaurants(records));
export const loadRestaurants = () => async (dispatch, getState, api) =>
{
try
{
dispatch(startLoading());
const records = await api.loadRestaurants();
dispatch(storeRestaurants(records));
} catch
{
dispatch(recordLoadingError())
}
};
const startLoading = () => ({ type: START_LOADING })
const storeRestaurants = records => ({
type: STORE_RESTAURANTS,
records
});
});
const recordLoadingError = () => ({ type: RECORD_LOADING_ERROR });