diff --git a/src/client/components/Library/Library.tsx b/src/client/components/Library/Library.tsx index b53911c..dda06f0 100644 --- a/src/client/components/Library/Library.tsx +++ b/src/client/components/Library/Library.tsx @@ -35,7 +35,7 @@ export const Library = (): ReactElement => { }, { pagination: { - size: 25, + size: 15, from: 0, }, type: "all", @@ -44,19 +44,33 @@ export const Library = (): ReactElement => { ), ); }, []); + const [{ pageIndex, pageSize }, setPagination] = + React.useState({ + pageIndex: 1, + pageSize: 15, + }); + + + const pagination = React.useMemo( + () => ({ + pageIndex, + pageSize, + }), + [pageIndex, pageSize] + ); const T2Table = (tableOptions): ReactElement => { const { columns, totalPages, rowClickHandler } = tableOptions; - const [{ pageIndex, pageSize }, setPagination] = - React.useState({ - pageIndex: 1, - pageSize: 25, - }) + + // pagination methods - const goToNextPage = useCallback((pageIndex, pageSize) => { - table.setPageIndex(pageSize); + const goToNextPage = useCallback(() => { + setPagination({ + pageIndex: pageIndex + 1, + pageSize, + }); dispatch( searchIssue( { @@ -75,14 +89,16 @@ export const Library = (): ReactElement => { }, []); - const goToPreviousPage = useCallback((pageIndex, pageSize) => { - console.log("papsdas", pageIndex); - // table.setPageIndex(pageIndex + 1) + const goToPreviousPage = useCallback(() => { + setPagination({ + pageIndex: pageIndex - 1, + pageSize, + }); let from = 0; if (pageIndex === 2) { - from = (pageIndex - 1) * pageSize + 2 - 27; + from = (pageIndex - 1) * pageSize + 2 - 17; } else { - from = (pageIndex - 1) * pageSize + 2 - 26; + from = (pageIndex - 1) * pageSize + 2 - 16; } dispatch( searchIssue( @@ -101,14 +117,19 @@ export const Library = (): ReactElement => { ); }, []); + + + const table = useReactTable({ data: searchResults.hits.hits, columns, manualPagination: true, getCoreRowModel: getCoreRowModel(), - - getFilteredRowModel: getFilteredRowModel(), - pageCount: totalPages, + pageCount: searchResults?.hits?.hits?.length ?? -1, + state: { + pagination, + }, + onPaginationChange: setPagination, // getPaginationRowModel: getPaginationRowModel(), debugTable: true, @@ -116,15 +137,15 @@ export const Library = (): ReactElement => { return ( <> - {/* pagination control */} -