Skip to content

Commit

Permalink
Fixed logic in calculating the nextCursor
Browse files Browse the repository at this point in the history
  • Loading branch information
TyroneAEM committed Apr 23, 2024
1 parent fcdfcd7 commit 741f0c7
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions blocks/gmo-campaign-list/gmo-campaign-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -407,6 +405,8 @@ function repaginate(dropdown) {
}

function nextPage(nextBtn) {
console.log('currentPageInfo');
console.log(currentPageInfo);

if (currentPageInfo.hasNextPage) {
//Calculate Next Page
Expand All @@ -426,6 +426,9 @@ function nextPage(nextBtn) {
}

function prevPage(prevBtn) {
console.log('currentPageInfo');
console.log(currentPageInfo);

if (currentPageInfo.hasPreviousPage) {
currentPage--;

Expand Down

0 comments on commit 741f0c7

Please sign in to comment.