Skip to content

Commit

Permalink
chore: Pagination constants
Browse files Browse the repository at this point in the history
Tweaks to pagination constants
  • Loading branch information
EthanFreestone committed Aug 29, 2023
1 parent 3ee4a49 commit fddb53f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
10 changes: 6 additions & 4 deletions lib/constants/pagination.js
Original file line number Diff line number Diff line change
@@ -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;
18 changes: 8 additions & 10 deletions lib/hooks/usePrevNextPagination.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}

Expand Down

0 comments on commit fddb53f

Please sign in to comment.