-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(explorer): As an end-user, I want to get more straight-forward i…
…nformation out of the issuer details page (#672) Co-authored-by: Alain Nicolas <alain.nicolas@consensys.net> Co-authored-by: Arthur <arthur@coeos.xyz>
- Loading branch information
1 parent
acbf663
commit 7d7a2c3
Showing
29 changed files
with
608 additions
and
135 deletions.
There are no files selected for viewing
File renamed without changes
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
File renamed without changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import { t } from "i18next"; | ||
import { ChevronLeft, ChevronRight } from "lucide-react"; | ||
import { useEffect, useRef, useState } from "react"; | ||
import { useSearchParams } from "react-router-dom"; | ||
|
||
import { ITEMS_PER_PAGE_DEFAULT } from "@/constants"; | ||
import { EQueryParams } from "@/enums/queryParams"; | ||
|
||
import { IBasicPaginationProps } from "./interface"; | ||
import { PerPageSelector } from "../PerPageSelector"; | ||
|
||
export const BasicPagination = ({ handlePage }: IBasicPaginationProps) => { | ||
const [searchParams, setSearchParams] = useSearchParams(); | ||
const [itemsPerPage, setItemsPerPage] = useState<string | number>( | ||
Number(searchParams.get(EQueryParams.ITEMS_PER_PAGE)) || ITEMS_PER_PAGE_DEFAULT, | ||
); | ||
const [currentPage, setCurrentPage] = useState<number>(1); | ||
|
||
useEffect(() => { | ||
handlePage(currentPage); | ||
}, [currentPage, handlePage, searchParams]); | ||
|
||
const itemsPerPageValues = [ITEMS_PER_PAGE_DEFAULT, 20, 50, 100]; | ||
|
||
const inputRef = useRef<HTMLInputElement>(null); | ||
|
||
const handlePageChange = (newPage: number) => { | ||
if (newPage >= 1 && inputRef && inputRef.current) { | ||
inputRef.current.value = newPage.toString(); | ||
searchParams.set(EQueryParams.PAGE, newPage.toString()); | ||
setSearchParams(searchParams); | ||
setCurrentPage(newPage); | ||
} | ||
}; | ||
|
||
const handleItemsPerPage = (val: number | string) => { | ||
setItemsPerPage(val); | ||
searchParams.set(EQueryParams.ITEMS_PER_PAGE, String(val)); | ||
setSearchParams(searchParams); | ||
}; | ||
const handlePreviousPage = () => handlePageChange(currentPage - 1); | ||
const handleNextPage = () => handlePageChange(currentPage + 1); | ||
|
||
const changePage = (inputPage: string) => { | ||
const page = Number(inputPage); | ||
inputPage.length && handlePageChange(page); | ||
}; | ||
|
||
const blurHandler = () => { | ||
!inputRef.current?.value.length && handlePageChange(currentPage); | ||
}; | ||
|
||
return ( | ||
<div className="flex justify-between items-center mt-8"> | ||
<div className="flex gap-3"> | ||
<button | ||
type="button" | ||
aria-label="Previous" | ||
onClick={handlePreviousPage} | ||
className="flex text-base font-semibold dark:text-whiteDefault hover:opacity-60 transition" | ||
> | ||
<ChevronLeft /> | ||
<span className="hidden md:inline-block">{t("common.actions.previous")}</span> | ||
</button> | ||
</div> | ||
<div className="flex items-center gap-3"> | ||
<input | ||
type="number" | ||
ref={inputRef} | ||
defaultValue={currentPage} | ||
onBlur={blurHandler} | ||
onChange={(event) => changePage(event.target.value)} | ||
className="w-16 h-8 px-2 border text-xs font-semibold dark:bg-transparent text-text-primary dark:text-whiteDefault text-center outline-none border-border-table dark:border-greyDark focus:border-border-inputFocus dark:focus:border-border-inputFocus rounded-lg transition" | ||
/> | ||
<PerPageSelector onChange={handleItemsPerPage} values={itemsPerPageValues} value={itemsPerPage} /> | ||
<span className="hidden md:inline-block text-slate-500 text-xs font-normal"> | ||
{t("common.messages.perPage")} | ||
</span> | ||
</div> | ||
<div className="flex gap-3"> | ||
<button | ||
type="button" | ||
aria-label="Next" | ||
onClick={handleNextPage} | ||
className="flex text-base font-semibold dark:text-whiteDefault hover:opacity-60 transition" | ||
> | ||
<span className="hidden md:inline-block">{t("common.actions.next")}</span> <ChevronRight /> | ||
</button> | ||
</div> | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export interface IBasicPaginationProps { | ||
handlePage: (page: number) => void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.