React-Redux-Scroll-Pagination-Delete

时间:2018-07-14 09:09:43

标签: reactjs redux pagination delete-row autoscroll

我正在建立帖子的自动滚动分页。我通过合并新页面的API数据和来自reducer的旧状态数据来做到这一点。

现在的问题是我在每个帖子上都具有删除功能。每次删除时,我都会从状态中删除记录,然后从数据库中删除记录。但是未能维护页面和记录。有人可以帮我知道在删除时该怎么办吗?

//Get Hiring Requests List...
case userConstants.GETALL_HIRINGREQUESTLIST_REQUEST:
  return { loading: true };
case userConstants.GETALL_HIRINGREQUESTLIST_FAILURE:
  return { error: action.error };
case userConstants.GETALL_HIRINGREQUESTLIST_SUCCESS:
  //console.log("here ", state);
  var updatedValues = "";
  if (!!state.allhiringrequests) {
    const oldstate = state.allhiringrequests;
    //console.log("Old value ", oldstate);
    const currentstate = action.users;
    //console.log("current value ", currentstate);
    if (oldstate.data !== undefined && currentstate.data.length > 0 && currentstate.paginationOptions.internalStatus != 2) {
      var updatedState = [...oldstate.data, ...currentstate.data]
      //console.log("New value here", updatedState);

      updatedValues = updatedState.filter(user => user.hiring_request_status === currentstate.data[0].hiring_request_status);
      //console.log("filtered value here", updatedValues);

      if (updatedState !== undefined) {
        var newobjct = {};
        newobjct.staus = action.users.status;
        newobjct.paginationOptions = action.users.paginationOptions;
        newobjct.data = updatedValues;
       // console.log("New value ", newobjct);
        return { allhiringrequests: newobjct }
      }
    } else {
      //console.log("blank state", action.users);
      return { allhiringrequests: action.users, loading: false };
    }
  }
  else {
    return { allhiringrequests: action.users, loading: false };
  }

对于删除,我编写了以下代码:

case userConstants.UPDATEHIRINGREQUEST_REQUEST:
  return { allhiringrequests: state.allhiringrequests };
case userConstants.UPDATEHIRINGREQUEST_SUCCESS:
  var updatedValues = "";
  if (!!state.allhiringrequests) {
    //console.log('# all requests');
    updatedValues = state.allhiringrequests.data.filter(user => user.hiringrequestdetailid !== action.id);
    //console.log('# all requests updates',updatedValues);
    var newobjct = {};
    newobjct.staus = state.allhiringrequests.status;
    newobjct.paginationOptions = state.allhiringrequests.paginationOptions;
    newobjct.data = updatedValues;
    //console.log("requests updates new ", newobjct);
    return { allhiringrequests: newobjct }
  } else {
    return { allhiringrequests: state.allhiringrequests }
  }
case userConstants.UPDATEHIRINGREQUEST_FAILURE:
  return { error: action.error }; 

0 个答案:

没有答案