import { usePdf, usePdfJump } from "@anaralabs/lector"; import { useEffect, useState } from "react"; import { useTranslation } from "@turbostarter/i18n"; import { Button } from "@turbostarter/ui-web/button"; import { Icons } from "@turbostarter/ui-web/icons"; export const PageNavigation = () => { const { t } = useTranslation("ai"); const pages = usePdf((state) => state.pdfDocumentProxy.numPages); const currentPage = usePdf((state) => state.currentPage); const [pageNumber, setPageNumber] = useState(currentPage); const { jumpToPage } = usePdfJump(); const handlePreviousPage = () => { if (currentPage > 1) { jumpToPage(currentPage - 1, { behavior: "auto" }); } }; const handleNextPage = () => { if (currentPage < pages) { jumpToPage(currentPage + 1, { behavior: "auto" }); } }; useEffect(() => { setPageNumber(currentPage); }, [currentPage]); return (
setPageNumber(e.target.value)} onBlur={(e) => { if (currentPage !== Number(e.target.value)) { jumpToPage(Number(e.target.value), { behavior: "auto", }); } }} onKeyDown={(e) => { if (e.key === "Enter") { e.currentTarget.blur(); } }} className="bg-accent focus:ring-primary/20 w-10 [appearance:textfield] rounded-md border-none text-center text-sm font-medium focus:ring-2 focus:outline-none [&::-webkit-inner-spin-button]:appearance-none [&::-webkit-outer-spin-button]:appearance-none" /> / {pages}
); };