This commit is contained in:
Almira Krdzic
2019-01-07 21:32:48 +01:00
parent 1c5a808a69
commit 81207c40ab

View File

@@ -20,9 +20,8 @@ moduleReducers[REQUEST_SHOP_PACKAGES] = (state, action) => {
moduleReducers[RECIEVE_SHOP_PACKAGES] = (state = {}, action) => {
// implement paging
// paging is implemented in a way that with every request one more package is requested on top of
// page size number
// this means that if retrieved number of packages is greater than page size there may be more packages
// paging is implemented in a way that requested number of packages is {page_size + 1}
// this way if retrieved number of packages is greater than page size there may be more packages
const shopPage = action.page || 1;
let shopPackages = [];
@@ -30,9 +29,8 @@ moduleReducers[RECIEVE_SHOP_PACKAGES] = (state = {}, action) => {
let retrievedShopPackages = action.shopPackages || [];
// append newly retrieved packages to existing ones if more packages are loaded
if (shopPage > state.shopPage) {
if (state.shopPage && shopPage > state.shopPage) {
shopPackages = state.loadedShopPackages || [];
// get ignored packages from previous request
const oldShopPackagesDiff = state.shopPackagesDiff || [];
// append packages ignored previous time to the beginning
@@ -46,6 +44,7 @@ moduleReducers[RECIEVE_SHOP_PACKAGES] = (state = {}, action) => {
while (retrievedShopPackages.length > SHOP_PAGE_SIZE) {
shopPackagesDiff.push(retrievedShopPackages.pop());
}
// append packages from this page to existing ones
shopPackages = shopPackages.concat(retrievedShopPackages);