feat(bookreader): escape for key close reader
This commit is contained in:
@@ -65,6 +65,12 @@ export function BookReader({ book, pages, onClose }: BookReaderProps) {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Erreur lors du chargement des URLs:", error);
|
console.error("Erreur lors du chargement des URLs:", error);
|
||||||
setImageError(true);
|
setImageError(true);
|
||||||
|
} finally {
|
||||||
|
// On s'assure que le chargement est terminé même en cas d'erreur
|
||||||
|
if (isMounted) {
|
||||||
|
setIsLoading(false);
|
||||||
|
setSecondPageLoading(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -5,9 +5,15 @@ interface UsePageNavigationProps {
|
|||||||
book: KomgaBook;
|
book: KomgaBook;
|
||||||
pages: number[];
|
pages: number[];
|
||||||
isDoublePage: boolean;
|
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 [currentPage, setCurrentPage] = useState(book.readProgress?.page || 1);
|
||||||
const [isLoading, setIsLoading] = useState(true);
|
const [isLoading, setIsLoading] = useState(true);
|
||||||
const [secondPageLoading, setSecondPageLoading] = useState(true);
|
const [secondPageLoading, setSecondPageLoading] = useState(true);
|
||||||
@@ -122,6 +128,8 @@ export const usePageNavigation = ({ book, pages, isDoublePage }: UsePageNavigati
|
|||||||
handlePreviousPage();
|
handlePreviousPage();
|
||||||
} else if (event.key === "ArrowRight") {
|
} else if (event.key === "ArrowRight") {
|
||||||
handleNextPage();
|
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("touchstart", handleTouchStart);
|
||||||
window.removeEventListener("touchend", handleTouchEnd);
|
window.removeEventListener("touchend", handleTouchEnd);
|
||||||
};
|
};
|
||||||
}, [handlePreviousPage, handleNextPage, handleTouchStart, handleTouchEnd]);
|
}, [handlePreviousPage, handleNextPage, handleTouchStart, handleTouchEnd, onClose]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
return () => {
|
return () => {
|
||||||
|
|||||||
@@ -44,3 +44,10 @@ export interface ControlButtonsProps {
|
|||||||
isDoublePage: boolean;
|
isDoublePage: boolean;
|
||||||
onToggleDoublePage: () => void;
|
onToggleDoublePage: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface UsePageNavigationProps {
|
||||||
|
book: KomgaBook;
|
||||||
|
pages: number[];
|
||||||
|
isDoublePage: boolean;
|
||||||
|
onClose?: () => void;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user