diff --git a/src/renderer/src/pages/catalogue/pagination.tsx b/src/renderer/src/pages/catalogue/pagination.tsx index eaaa97a8..1ba02d06 100644 --- a/src/renderer/src/pages/catalogue/pagination.tsx +++ b/src/renderer/src/pages/catalogue/pagination.tsx @@ -2,6 +2,7 @@ import { Button } from "@renderer/components/button/button"; import { ChevronLeftIcon, ChevronRightIcon } from "@primer/octicons-react"; import { useFormat } from "@renderer/hooks/use-format"; import { useEffect, useRef, useState } from "react"; +import type { ChangeEvent, KeyboardEvent } from "react"; import "./pagination.scss"; interface PaginationProps { @@ -44,6 +45,66 @@ export function Pagination({ startPage = Math.max(1, endPage - visiblePages + 1); } + const onJumpChange = (e: ChangeEvent) => { + const val = e.target.value; + if (val === "") { + setJumpValue(""); + return; + } + const num = Number(val); + if (Number.isNaN(num)) { + return; + } + if (num < 1) { + setJumpValue("1"); + return; + } + if (num > totalPages) { + setJumpValue(String(totalPages)); + return; + } + setJumpValue(val); + }; + + const onJumpKeyDown = (e: KeyboardEvent) => { + if (e.key === "Enter") { + if (jumpValue.trim() === "") return; + const parsed = Number(jumpValue); + if (Number.isNaN(parsed)) return; + const target = Math.max(1, Math.min(totalPages, parsed)); + onPageChange(target); + setIsJumpOpen(false); + } else if (e.key === "Escape") { + setIsJumpOpen(false); + } + }; + + const JumpControl = () => + isJumpOpen ? ( + { + setIsJumpOpen(false); + }} + aria-label="Go to page" + /> + ) : ( + + ); + return (
{startPage > 1 && ( @@ -77,60 +138,7 @@ export function Pagination({ > {formatNumber(1)} - {isJumpOpen ? ( - { - const val = e.target.value; - if (val === "") { - setJumpValue(""); - return; - } - const num = Number(val); - if (Number.isNaN(num)) { - return; - } - if (num < 1) { - setJumpValue("1"); - return; - } - if (num > totalPages) { - setJumpValue(String(totalPages)); - return; - } - setJumpValue(val); - }} - onKeyDown={(e) => { - if (e.key === "Enter") { - if (jumpValue.trim() === "") return; - const parsed = Number(jumpValue); - if (Number.isNaN(parsed)) return; - const target = Math.max(1, Math.min(totalPages, parsed)); - onPageChange(target); - setIsJumpOpen(false); - } else if (e.key === "Escape") { - setIsJumpOpen(false); - } - }} - onBlur={() => { - setIsJumpOpen(false); - }} - aria-label="Go to page" - /> - ) : ( - - )} + )} @@ -150,60 +158,7 @@ export function Pagination({ {!isLastThree && page < totalPages - 1 && ( <> - {isJumpOpen ? ( - { - const val = e.target.value; - if (val === "") { - setJumpValue(""); - return; - } - const num = Number(val); - if (Number.isNaN(num)) { - return; - } - if (num < 1) { - setJumpValue("1"); - return; - } - if (num > totalPages) { - setJumpValue(String(totalPages)); - return; - } - setJumpValue(val); - }} - onKeyDown={(e) => { - if (e.key === "Enter") { - if (jumpValue.trim() === "") return; - const parsed = Number(jumpValue); - if (Number.isNaN(parsed)) return; - const target = Math.max(1, Math.min(totalPages, parsed)); - onPageChange(target); - setIsJumpOpen(false); - } else if (e.key === "Escape") { - setIsJumpOpen(false); - } - }} - onBlur={() => { - setIsJumpOpen(false); - }} - aria-label="Go to page" - /> - ) : ( - - )} +