diff --git a/.gitignore b/.gitignore index 63da9a3..8cbfc60 100644 --- a/.gitignore +++ b/.gitignore @@ -50,3 +50,6 @@ node_modules/ /playwright-report/ /blob-report/ /playwright/.cache/ + +# vscode +.vscode \ No newline at end of file diff --git a/src/components/player/Navigator.tsx b/src/components/player/Navigator.tsx index 2c316c0..eafa487 100644 --- a/src/components/player/Navigator.tsx +++ b/src/components/player/Navigator.tsx @@ -1,12 +1,46 @@ 'use client'; import { Button } from '@headlessui/react'; +import { useState, useEffect, useRef } from 'react'; export const Navigator = ({ currentPage, numPages, skipToLocation }: { currentPage: number; numPages: number | undefined; skipToLocation: (location: string | number, shouldPause?: boolean) => void; }) => { + const [inputValue, setInputValue] = useState(currentPage.toString()); + const inputRef = useRef(null); + + useEffect(() => { + setInputValue(currentPage.toString()); + }, [currentPage]); + + const handleInputChange = (e: React.ChangeEvent) => { + // Only allow numbers + const value = e.target.value.replace(/[^0-9]/g, ''); + setInputValue(value); + }; + + const handleInputConfirm = () => { + let page = parseInt(inputValue, 10); + if (isNaN(page)) return; + const maxPage = numPages || 1; + if (page < 1) page = 1; + if (page > maxPage) page = maxPage; + if (page !== currentPage) { + skipToLocation(page, true); + } else { + setInputValue(page.toString()); // reset input if unchanged + } + }; + + const handleInputKeyDown = (e: React.KeyboardEvent) => { + if (e.key === 'Enter') { + handleInputConfirm(); + inputRef.current?.blur(); + } + }; + return (
{/* Page back */} @@ -21,11 +55,21 @@ export const Navigator = ({ currentPage, numPages, skipToLocation }: { - {/* Page number */} -
-

- {currentPage} / {numPages || 1} -

+ {/* Page number input */} +
+ + / {numPages || 1}
{/* Page forward */}