diff --git a/apps/readest-app/src/app/library/components/BookItem.tsx b/apps/readest-app/src/app/library/components/BookItem.tsx index 9c0e0ab5..0d4cda52 100644 --- a/apps/readest-app/src/app/library/components/BookItem.tsx +++ b/apps/readest-app/src/app/library/components/BookItem.tsx @@ -33,6 +33,10 @@ interface BookItemProps { showBookDetailsModal: (book: Book) => void; } +const CELL_ASPECT_RATIO = 28 / 41; +const MIN_FIT_COVER_WIDTH_RATIO = 0.72; +const MIN_FIT_COVER_HEIGHT_RATIO = 0.78; + const BookItem: React.FC = ({ book, mode, @@ -56,17 +60,66 @@ const BookItem: React.FC = ({ setCoverAspect(null); }, [book.hash, book.metadata?.coverImageUrl, book.coverImageUrl]); - const CELL_ASPECT_RATIO = 28 / 41; + const measuredCoverAspect = coverAspect ?? CELL_ASPECT_RATIO; const fitCoverInGrid = mode === 'grid' && coverFit === 'fit' && coverAspect !== null; - const shouldShrinkWidth = fitCoverInGrid && coverAspect! < CELL_ASPECT_RATIO; + const fitCoverBaseWidthRatio = + fitCoverInGrid && measuredCoverAspect < CELL_ASPECT_RATIO + ? measuredCoverAspect / CELL_ASPECT_RATIO + : 1; + const fitCoverBaseHeightRatio = + fitCoverInGrid && measuredCoverAspect > CELL_ASPECT_RATIO + ? CELL_ASPECT_RATIO / measuredCoverAspect + : 1; + const fitCoverWidthRatio = fitCoverInGrid + ? Math.max(MIN_FIT_COVER_WIDTH_RATIO, fitCoverBaseWidthRatio) + : 1; + const fitCoverHeightRatio = fitCoverInGrid + ? Math.max(MIN_FIT_COVER_HEIGHT_RATIO, fitCoverBaseHeightRatio) + : 1; + const fitCoverIsZoomed = + fitCoverInGrid && + (fitCoverWidthRatio > fitCoverBaseWidthRatio || fitCoverHeightRatio > fitCoverBaseHeightRatio); const bookitemMainStyle = fitCoverInGrid ? { - aspectRatio: coverAspect!, - ...(shouldShrinkWidth ? { width: `${(coverAspect! / CELL_ASPECT_RATIO) * 100}%` } : {}), + width: `${fitCoverWidthRatio * 100}%`, + height: `${fitCoverHeightRatio * 100}%`, } : undefined; const seriesText = formatSeries(book.metadata?.series, book.metadata?.seriesIndex); + const coverNode = ( +
+ + {bookSelected && ( +
+ )} + {isSelectMode && ( +
+ {bookSelected ? ( + + ) : ( + + )} +
+ )} +
+ ); return (
= ({ )} onClick={(e) => e.stopPropagation()} > -
- - {bookSelected && ( -
- )} - {isSelectMode && ( -
- {bookSelected ? ( - - ) : ( - - )} -
- )} -
+ {mode === 'grid' ? ( +
{coverNode}
+ ) : ( + coverNode + )}