From e3cea24615abd0a6d6ad4ad03888e2a38054c227 Mon Sep 17 00:00:00 2001 From: Rishi Ghan Date: Mon, 7 Nov 2022 21:15:02 -0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20Using=20the=20refactored=20T2Tab?= =?UTF-8?q?le=20for=20Wanted=20Comics?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/WantedComics/WantedComics.tsx | 76 ++++++++++++++++--- 1 file changed, 67 insertions(+), 9 deletions(-) diff --git a/src/client/components/WantedComics/WantedComics.tsx b/src/client/components/WantedComics/WantedComics.tsx index 9d720fa..da767dc 100644 --- a/src/client/components/WantedComics/WantedComics.tsx +++ b/src/client/components/WantedComics/WantedComics.tsx @@ -1,4 +1,4 @@ -import React, { ReactElement, useEffect, useMemo } from "react"; +import React, { ReactElement, useCallback, useEffect, useMemo } from "react"; import { useDispatch, useSelector } from "react-redux"; import { searchIssue } from "../../actions/fileops.actions"; import SearchBar from "../Library/SearchBar"; @@ -86,23 +86,81 @@ export const WantedComics = (props): ReactElement => { }, ]; + /** + * Pagination control that fetches the next x (pageSize) items + * based on the y (pageIndex) offset from the Elasticsearch index + * @param {number} pageIndex + * @param {number} pageSize + * @returns void + * + **/ + const nextPage = useCallback((pageIndex: number, pageSize: number) => { + dispatch( + searchIssue( + { + query: {}, + }, + { + pagination: { + size: pageSize, + from: pageSize * pageIndex + 1, + }, + type: "all", + trigger: "wantedComicsPage", + }, + ), + ); + }, []); + + + /** + * Pagination control that fetches the previous x (pageSize) items + * based on the y (pageIndex) offset from the Elasticsearch index + * @param {number} pageIndex + * @param {number} pageSize + * @returns void + **/ + const previousPage = useCallback((pageIndex: number, pageSize: number) => { + let from = 0; + if (pageIndex === 2) { + from = (pageIndex - 1) * pageSize + 2 - 17; + } else { + from = (pageIndex - 1) * pageSize + 2 - 16; + } + dispatch( + searchIssue( + { + query: {}, + }, + { + pagination: { + size: pageSize, + from, + }, + type: "all", + trigger: "wantedComicsPage" + }, + ), + ); + }, []); + return (
-

Wanted Comics

- {/* Search bar */} - +
+

Wanted Comics

+
{!isEmpty(wantedComics) && (
{/* pagination controls */}