Skip to content

Commit

Permalink
refactor: Changed hasNextPage functionality
Browse files Browse the repository at this point in the history
Now the hasNextPage overwrites the canGoNext calculation if it is provided
  • Loading branch information
Jack-Golding committed May 13, 2024
1 parent 47d5c71 commit f480712
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/hooks/usePrevNextPagination.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@ import {

import useLocalPageStore from './useLocalPageStore';

// Currently there are several places in which this hook is used twice within the same component
// Once in order to get the current page, and again in order to handle changes to paginations
// This hook should be refactored in order to resolve these issue - @EthanFreestone
const usePrevNextPagination = ({
count = 0, // Only needed for reading back MCL props
defaultToPageOne = true, // A prop to allow the implementor to turn off the defaulting to page=1
pageSize = DEFAULT_PAGINATION_SIZE, // Only needed for reading back MCL props
id = DEFAULT_PAGE_KEY, // This id is ONLY used for syncToLocation: false cases, as a key to the zustand store
syncToLocation = true, // Used to turn on/off location syncing, so can be used as standalone state if required,
hasNextPage = false
hasNextPage = null // Override for canGoNext, used in the case in which resources are fetched with no stats
} = {}) => {
/* ------ ZUSTAND STORE ------ */
// For NON-SYNC-TO-LOCATION use cases, store the currentPage in a keyed store
Expand Down Expand Up @@ -147,7 +150,7 @@ const usePrevNextPagination = ({
]);

// Set up MCL specific props based on page
const pagingCanGoNext = currentPage && (currentPage < Number(count) / pageSize || hasNextPage);
const pagingCanGoNext = hasNextPage ?? (currentPage && (currentPage < Number(count) / pageSize));
const pagingCanGoPrevious = currentPage && Number(currentPage) > 1;
const pagingOffset = currentPage ? (currentPage - 1) * pageSize : 0;
const onNeedMoreData = (...args) => {
Expand Down

0 comments on commit f480712

Please sign in to comment.