feat(bookreader): escape for key close reader

This commit is contained in:
Julien Froidefond
2025-02-16 17:37:47 +01:00
parent 2f1dfb8e9a
commit 62114b8fcb
3 changed files with 23 additions and 2 deletions

View File

@@ -5,9 +5,15 @@ interface UsePageNavigationProps {
book: KomgaBook;
pages: number[];
isDoublePage: boolean;
onClose: () => void;
}
export const usePageNavigation = ({ book, pages, isDoublePage }: UsePageNavigationProps) => {
export const usePageNavigation = ({
book,
pages,
isDoublePage,
onClose,
}: UsePageNavigationProps) => {
const [currentPage, setCurrentPage] = useState(book.readProgress?.page || 1);
const [isLoading, setIsLoading] = useState(true);
const [secondPageLoading, setSecondPageLoading] = useState(true);
@@ -122,6 +128,8 @@ export const usePageNavigation = ({ book, pages, isDoublePage }: UsePageNavigati
handlePreviousPage();
} else if (event.key === "ArrowRight") {
handleNextPage();
} else if (event.key === "Escape" && onClose) {
onClose();
}
};
@@ -134,7 +142,7 @@ export const usePageNavigation = ({ book, pages, isDoublePage }: UsePageNavigati
window.removeEventListener("touchstart", handleTouchStart);
window.removeEventListener("touchend", handleTouchEnd);
};
}, [handlePreviousPage, handleNextPage, handleTouchStart, handleTouchEnd]);
}, [handlePreviousPage, handleNextPage, handleTouchStart, handleTouchEnd, onClose]);
useEffect(() => {
return () => {