From 741f0c78ce7a9a3230b4db706c06fb953fc0aed5 Mon Sep 17 00:00:00 2001 From: Tyrone Tse Date: Tue, 23 Apr 2024 15:05:44 -0500 Subject: [PATCH] Fixed logic in calculating the nextCursor --- blocks/gmo-campaign-list/gmo-campaign-list.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/blocks/gmo-campaign-list/gmo-campaign-list.js b/blocks/gmo-campaign-list/gmo-campaign-list.js index 5a4ade4c..3782f1e2 100644 --- a/blocks/gmo-campaign-list/gmo-campaign-list.js +++ b/blocks/gmo-campaign-list/gmo-campaign-list.js @@ -136,19 +136,17 @@ export default async function decorate(block, numPerPage = currentNumberPerPage, const campaignPaginatedResponse = await graphqlAllCampaigns(numPerPage, cursor); const campaigns = campaignPaginatedResponse.data.campaignPaginated.edges; currentPageInfo = campaignPaginatedResponse.data.campaignPaginated.pageInfo; + + currentPageInfo.nextCursor = campaigns[campaigns.length - 1].cursor; if (!previousPage && !nextPage) { cursorArray = campaigns.map(item => item.cursor); - currentPageInfo.nextCursor = campaigns[campaigns.length - 1].cursor; } else if (nextPage){ campaigns.forEach(item => { cursorArray.push(item.cursor); }); - - currentPageInfo.nextCursor = campaigns[campaigns.length - 1].cursor; - } currentPageInfo.itemCount = campaigns.length; @@ -407,6 +405,8 @@ function repaginate(dropdown) { } function nextPage(nextBtn) { +console.log('currentPageInfo'); +console.log(currentPageInfo); if (currentPageInfo.hasNextPage) { //Calculate Next Page @@ -426,6 +426,9 @@ function nextPage(nextBtn) { } function prevPage(prevBtn) { +console.log('currentPageInfo'); +console.log(currentPageInfo); + if (currentPageInfo.hasPreviousPage) { currentPage--;