Added loading state for getting data from redux store

This commit is contained in:
Daniel Weissmall 2022-11-13 01:53:51 +03:00
parent 4312533d5c
commit be4587f7cc
2 changed files with 3 additions and 3 deletions

View File

@ -20,8 +20,8 @@ const useArticleCommonStore = (): ArticleStore => {
setError(true);
return null;
}
setLoading(false);
setCurrentArticle(fromStore);
setLoading(false);
return fromStore;
}
setLoading(false);

View File

@ -17,13 +17,13 @@ const articleReducer = (
): ArticleStoreState => {
switch (action.type) {
case actionTypes.SET_ARTICLE:
return { ...state, articles: action.updatedList, currentArticle: action.article, hasError: typeof action.article === undefined };
return { ...state, articles: action.updatedList, currentArticle: action.article, hasError: typeof action.article === undefined, isLoading: false };
case actionTypes.GET_ARTICLE:
return { ...state, isLoading: true };
case actionTypes.GET_ARTICLE_SUCCESS:
return { ...state, isLoading: false, currentArticle: action.payload };
case actionTypes.GET_ARTICLE_FAILURE:
return { ...state, hasError: true, isLoading: false };
return { ...state, hasError: false, isLoading: true };
default:
return state;
}