From fddb53f3ed8c50a55393a859dd97e0ecbc84e561 Mon Sep 17 00:00:00 2001 From: Ethan Freestone Date: Tue, 29 Aug 2023 18:05:59 +0100 Subject: [PATCH] chore: Pagination constants Tweaks to pagination constants --- lib/constants/pagination.js | 10 ++++++---- lib/hooks/usePrevNextPagination.js | 18 ++++++++---------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/constants/pagination.js b/lib/constants/pagination.js index 0114dbc3..7e0d213e 100644 --- a/lib/constants/pagination.js +++ b/lib/constants/pagination.js @@ -1,6 +1,8 @@ export const NEXT = 'next'; export const PREV = 'prev'; -export const pagination = { - NEXT, - PREV -}; + +// THIS SHOULD BE SET BY CALLING CODE, ONLY DEFAULTED TO AVOID DIVISION BY UNDEFINED +export const DEFAULT_PAGINATION_SIZE = 25; +// Only here because we need argument 3 from onNeedMoreData +// and want to avoid "magic number" sonarlint +export const MCL_NEED_MORE_DATA_PREV_NEXT_ARG_INDEX = 3; diff --git a/lib/hooks/usePrevNextPagination.js b/lib/hooks/usePrevNextPagination.js index c46301ab..02328967 100644 --- a/lib/hooks/usePrevNextPagination.js +++ b/lib/hooks/usePrevNextPagination.js @@ -2,14 +2,12 @@ import { useCallback, useEffect, useMemo, useState } from 'react'; import { useLocation, useHistory } from 'react-router-dom'; import queryString from 'query-string'; -import { pagination } from '../constants'; - -// THIS SHOULD BE SET BY CALLING CODE, ONLY DEFAULTED TO AVOID DIVISION BY UNDEFINED -const DEFAULT_PAGINATION_SIZE = 25; - -// Only here because we need argument 3 from onNeedMoreData -// and want to avoid "magic number" sonarlint -const MCL_NEED_MORE_DATA_PREV_NEXT_ARG_INDEX = 3; +import { + DEFAULT_PAGINATION_SIZE, + MCL_NEED_MORE_DATA_PREV_NEXT_ARG_INDEX, + NEXT, + PREV +} from '../constants'; const usePrevNextPagination = ({ count = 0, // Only needed for reading back MCL props @@ -24,9 +22,9 @@ const usePrevNextPagination = ({ const urlQuery = queryString.parse(location.search); let newPage; - if (direction === pagination.NEXT) { + if (direction === NEXT) { newPage = currentPage + 1; - } else if (direction === pagination.PREV) { + } else if (direction === PREV) { newPage = currentPage - 1; }