AllenYuan

pagination - update articleList reducer

Apr 19th, 2020
423
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. src/reducers/articleList.js
  2.  
  3. export default (state = {}, action) => {
  4.   switch (action.type) {
  5.     case 'HOME_PAGE_LOADED':
  6.       return {
  7.         ...state,
  8.         articles: action.payload[1].articles,
  9.         articlesCount: action.payload[1].articlesCount,
  10.         tab: action.tab,
  11.         currentPage: 0
  12.       };
  13.     case 'HOME_PAGE_UNLOADED':
  14.       return {};
  15.     case 'CHANGE_TAB':
  16.       return {
  17.         ...state,
  18.         articles: action.payload.articles,
  19.         articlesCount: action.payload.articlesCount,
  20.         tab: action.tab,
  21.         tag: null,
  22.         currentPage: 0
  23.       };
  24.     // update article data and set the current page
  25.     case 'SET_PAGE':
  26.       return {
  27.         ...state,
  28.         articles: action.payload.articles,
  29.         articlesCount: action.payload.articlesCount,
  30.         currentPage: action.page
  31.       };
  32.     case 'APPLY_TAG_FILTER':
  33.       return {
  34.         ...state,
  35.         articles: action.payload.articles,
  36.         articlesCount: action.payload.articlesCount,
  37.         tab: null,
  38.         tag: action.tag,
  39.         currentPage: 0
  40.       };
  41.     case 'PROFILE_PAGE_LOADED':
  42.     case 'PROFILE_FAVORITES_PAGE_LOADED':
  43.       return {
  44.         ...state,
  45.         articles: action.payload[1].articles,
  46.         articlesCount: action.payload[1].articlesCount,
  47.         currentPage: 0
  48.       };
  49.     case 'PROFILE_PAGE_UNLOADED':
  50.     case 'PROFILE_FAVORITES_PAGE_UNLOADED':
  51.       return {};
  52.   }
  53.  
  54.   return state;
  55. };
Advertisement
Add Comment
Please, Sign In to add comment