Some checks failed
Deploy with Docker Compose / deploy (push) Has been cancelled
- Introduce provider abstraction layer (IMediaProvider, KomgaProvider, StripstreamProvider) - Add Stripstream Librarian as second media provider with full feature parity - Migrate all pages and components from direct Komga services to provider factory - Remove dead service code (BaseApiService, HomeService, LibraryService, SearchService, TestService) - Fix library/series page-based pagination for both providers (Komga 0-indexed, Stripstream 1-indexed) - Fix unread filter and search on library page for both providers - Fix read progress display for Stripstream (reading_status mapping) - Fix series read status (books_read_count) for Stripstream - Add global search with series results for Stripstream (series_hits from Meilisearch) - Fix thumbnail proxy to return 404 gracefully instead of JSON on upstream error - Replace duration-based cache debug detection with x-nextjs-cache header Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
56 lines
1.9 KiB
TypeScript
56 lines
1.9 KiB
TypeScript
import { useState, useCallback, useEffect } from "react";
|
|
import type { NormalizedBook } from "@/lib/providers/types";
|
|
|
|
interface UseThumbnailsProps {
|
|
book: NormalizedBook;
|
|
currentPage: number;
|
|
}
|
|
|
|
export const useThumbnails = ({ book, currentPage }: UseThumbnailsProps) => {
|
|
const [loadedThumbnails, setLoadedThumbnails] = useState<{ [key: number]: boolean }>({});
|
|
const [visibleThumbnails, setVisibleThumbnails] = useState<number[]>([]);
|
|
|
|
const handleThumbnailLoad = useCallback((pageNumber: number) => {
|
|
setLoadedThumbnails((prev) => ({ ...prev, [pageNumber]: true }));
|
|
}, []);
|
|
|
|
const getThumbnailUrl = useCallback(
|
|
(pageNumber: number) => {
|
|
// Derive page URL from the book's thumbnailUrl provider pattern
|
|
if (book.thumbnailUrl.startsWith("/api/stripstream/")) {
|
|
return `/api/stripstream/images/books/${book.id}/pages/${pageNumber}`;
|
|
}
|
|
return `/api/komga/images/books/${book.id}/pages/${pageNumber}/thumbnail?zero_based=true`;
|
|
},
|
|
[book.id, book.thumbnailUrl]
|
|
);
|
|
|
|
// Mettre à jour les thumbnails visibles autour de la page courante
|
|
useEffect(() => {
|
|
const windowSize = 0; // DÉSACTIVÉ TEMPORAIREMENT: Thumbnails désactivés pour éviter de surcharger Komga
|
|
const start = Math.max(1, currentPage - windowSize);
|
|
const end = currentPage + windowSize;
|
|
const newVisibleThumbnails = Array.from({ length: end - start + 1 }, (_, i) => start + i);
|
|
setVisibleThumbnails(newVisibleThumbnails);
|
|
}, [currentPage]);
|
|
|
|
const scrollToActiveThumbnail = useCallback(() => {
|
|
const thumbnail = document.getElementById(`thumbnail-${currentPage}`);
|
|
if (thumbnail) {
|
|
thumbnail.scrollIntoView({
|
|
behavior: "smooth",
|
|
block: "nearest",
|
|
inline: "center",
|
|
});
|
|
}
|
|
}, [currentPage]);
|
|
|
|
return {
|
|
loadedThumbnails,
|
|
handleThumbnailLoad,
|
|
getThumbnailUrl,
|
|
visibleThumbnails,
|
|
scrollToActiveThumbnail,
|
|
};
|
|
};
|