Skip to content
This repository has been archived by the owner on Sep 8, 2021. It is now read-only.

Fixed small bug of reducer #115

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions src/reducers/articleList.js
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -32,15 +33,15 @@ export default (state = {}, action) => {
case SET_PAGE:
return {
...state,
articles: action.payload.articles,
articles: action.payload.articles || [],
articlesCount: action.payload.articlesCount,
currentPage: action.page
};
case APPLY_TAG_FILTER:
return {
...state,
pager: action.pager,
articles: action.payload.articles,
articles: action.payload.articles || [],
articlesCount: action.payload.articlesCount,
tab: null,
tag: action.tag,
Expand All @@ -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
};
Expand All @@ -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,
Expand All @@ -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:
Expand Down
1 change: 1 addition & 0 deletions src/reducers/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export default (state = {}, action) => {
switch (action.type) {
case LOGIN:
case REGISTER:
if (!action.payload) return state;
return {
...state,
inProgress: false,
Expand Down
3 changes: 2 additions & 1 deletion src/reducers/home.js
Original file line number Diff line number Diff line change
@@ -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 {};
Expand Down