diff --git a/src/reducers/articleList.js b/src/reducers/articleList.js index 1fe962daa..276401fa5 100644 --- a/src/reducers/articleList.js +++ b/src/reducers/articleList.js @@ -13,6 +13,7 @@ import { } from '../constants/actionTypes'; export default (state = {}, action) => { + if (!action.payload) return state; switch (action.type) { case ARTICLE_FAVORITED: case ARTICLE_UNFAVORITED: @@ -32,7 +33,7 @@ export default (state = {}, action) => { case SET_PAGE: return { ...state, - articles: action.payload.articles, + articles: action.payload.articles || [], articlesCount: action.payload.articlesCount, currentPage: action.page }; @@ -40,7 +41,7 @@ export default (state = {}, action) => { return { ...state, pager: action.pager, - articles: action.payload.articles, + articles: action.payload.articles || [], articlesCount: action.payload.articlesCount, tab: null, tag: action.tag, @@ -50,9 +51,9 @@ export default (state = {}, action) => { return { ...state, pager: action.pager, - tags: action.payload[0].tags, - articles: action.payload[1].articles, - articlesCount: action.payload[1].articlesCount, + tags: (!!action.payload[0] && action.payload[0].tags) || [], + articles: (!!action.payload[1] && action.payload[1].articles) || [], + articlesCount: !!action.payload[1] && action.payload[1].articlesCount, currentPage: 0, tab: action.tab }; @@ -62,7 +63,7 @@ export default (state = {}, action) => { return { ...state, pager: action.pager, - articles: action.payload.articles, + articles: action.payload.articles || [], articlesCount: action.payload.articlesCount, tab: action.tab, currentPage: 0, @@ -73,8 +74,8 @@ export default (state = {}, action) => { return { ...state, pager: action.pager, - articles: action.payload[1].articles, - articlesCount: action.payload[1].articlesCount, + articles: (!!action.payload[1] && action.payload[1].articles) || [], + articlesCount: !!action.payload[1] && action.payload[1].articlesCount, currentPage: 0 }; case PROFILE_PAGE_UNLOADED: diff --git a/src/reducers/auth.js b/src/reducers/auth.js index 6e8383866..e32b23c46 100644 --- a/src/reducers/auth.js +++ b/src/reducers/auth.js @@ -11,6 +11,7 @@ export default (state = {}, action) => { switch (action.type) { case LOGIN: case REGISTER: + if (!action.payload) return state; return { ...state, inProgress: false, diff --git a/src/reducers/home.js b/src/reducers/home.js index c1cd49af1..3925dee55 100644 --- a/src/reducers/home.js +++ b/src/reducers/home.js @@ -1,11 +1,12 @@ import { HOME_PAGE_LOADED, HOME_PAGE_UNLOADED } from '../constants/actionTypes'; export default (state = {}, action) => { + if (!action.payload) return state; switch (action.type) { case HOME_PAGE_LOADED: return { ...state, - tags: action.payload[0].tags + tags: (!!action.payload[0] && action.payload[0].tags) || [] }; case HOME_PAGE_UNLOADED: return {};