Skip to content

Commit

Permalink
Merge pull request #495 from shinyichen/SCIX-438-reference-pagination
Browse files Browse the repository at this point in the history
Fix abstract query page param
  • Loading branch information
shinyichen authored Jul 9, 2024
2 parents 9f8a7b7 + 3bd4c56 commit 1239f0f
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/lib/useGetAbstractParams.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
import { AppState, useStore } from '@/store';
import { useCallback, useEffect, useRef, useState } from 'react';

/**
* Helper hook for handling pagination in abstract subpages
*/
export const useGetAbstractParams = (id: string) => {
const [start, setStart] = useState(0);
const pageSize = useStore((state: AppState) => state.numPerPage);

const prev = useRef<string>();
useEffect(() => {
prev.current = id;
});

// reset start if the previous bibcode is different than the current
const getParams = useCallback(() => ({ bibcode: id, start: prev.current === id ? start : 0 }), [id, start]);
const getParams = useCallback(
() => ({ bibcode: id, start: prev.current === id ? start * pageSize : 0 }),
[id, start, pageSize],
);
return { getParams, onPageChange: setStart };
};

0 comments on commit 1239f0f

Please sign in to comment.