Set static size for manga details page covers

This commit is contained in:
schroda
2024-10-07 13:29:25 +02:00
parent cd7ec05ce3
commit d9b633900c
4 changed files with 19 additions and 15 deletions

View File

@@ -0,0 +1,9 @@
/*
* Copyright (C) Contributors to the Suwayomi project
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
export const MANGA_COVER_ASPECT_RATIO = '1 / 1.5';

View File

@@ -44,6 +44,7 @@ import { useLocalStorage } from '@/modules/core/hooks/useStorage.tsx';
import { useResizeObserver } from '@/modules/core/hooks/useResizeObserver.tsx'; import { useResizeObserver } from '@/modules/core/hooks/useResizeObserver.tsx';
import { useMetadataServerSettings } from '@/modules/settings/services/ServerSettingsMetadata.ts'; import { useMetadataServerSettings } from '@/modules/settings/services/ServerSettingsMetadata.ts';
import { shouldForwardProp } from '@/modules/core/utils/ShouldForwardProp.ts'; import { shouldForwardProp } from '@/modules/core/utils/ShouldForwardProp.ts';
import { MANGA_COVER_ASPECT_RATIO } from '@/modules/manga/Manga.constants.ts';
const DetailsWrapper = styled('div')(({ theme }) => ({ const DetailsWrapper = styled('div')(({ theme }) => ({
display: 'flex', display: 'flex',
@@ -141,15 +142,7 @@ const Thumbnail = ({ manga }: { manga: Partial<MangaThumbnailInfo> }) => {
const popupState = usePopupState({ variant: 'popover', popupId: 'manga-thumbnail-fullscreen' }); const popupState = usePopupState({ variant: 'popover', popupId: 'manga-thumbnail-fullscreen' });
const [imageHeight, setImageHeight] = useState<number>();
const [imageElement, setImageElement] = useState<HTMLImageElement | null>(null);
useResizeObserver(
imageElement,
useCallback(() => setImageHeight(imageElement?.clientHeight), [imageElement]),
);
const [isImageReady, setIsImageReady] = useState(false); const [isImageReady, setIsImageReady] = useState(false);
const isImageHeightReady = isImageReady && !!imageHeight;
return ( return (
<> <>
@@ -160,23 +153,23 @@ const Thumbnail = ({ manga }: { manga: Partial<MangaThumbnailInfo> }) => {
overflow: 'hidden', overflow: 'hidden',
backgroundColor: 'background.paper', backgroundColor: 'background.paper',
width: '150px', width: '150px',
height: `${isImageHeightReady ? imageHeight : 225}px`, maxHeight: 'fit-content',
aspectRatio: MANGA_COVER_ASPECT_RATIO,
flexShrink: 0, flexShrink: 0,
flexGrow: 0,
[theme.breakpoints.up('lg')]: { [theme.breakpoints.up('lg')]: {
width: '200px', width: '200px',
height: `${isImageHeightReady ? imageHeight : 300}px`,
}, },
[theme.breakpoints.up('xl')]: { [theme.breakpoints.up('xl')]: {
width: '300px', width: '300px',
height: `${isImageHeightReady ? imageHeight : 450}px`,
}, },
}} }}
> >
<SpinnerImage <SpinnerImage
ref={setImageElement}
src={Mangas.getThumbnailUrl(manga)} src={Mangas.getThumbnailUrl(manga)}
alt="Manga Thumbnail" alt="Manga Thumbnail"
onImageLoad={() => setIsImageReady(true)} onImageLoad={() => setIsImageReady(true)}
imgStyle={{ width: '100%', height: '100%', objectFit: 'cover' }}
/> />
{isImageReady && ( {isImageReady && (
<Stack <Stack
@@ -203,7 +196,7 @@ const Thumbnail = ({ manga }: { manga: Partial<MangaThumbnailInfo> }) => {
<Modal {...bindPopover(popupState)} sx={{ outline: 0 }}> <Modal {...bindPopover(popupState)} sx={{ outline: 0 }}>
<Stack <Stack
onClick={() => popupState.close()} onClick={() => popupState.close()}
sx={{ height: '100vh', py: 2, outline: 0, justifyContent: 'center', alignItems: 'center' }} sx={{ height: '100vh', p: 2, outline: 0, justifyContent: 'center', alignItems: 'center' }}
> >
<SpinnerImage <SpinnerImage
src={Mangas.getThumbnailUrl(manga)} src={Mangas.getThumbnailUrl(manga)}

View File

@@ -21,6 +21,7 @@ import { GridLayout } from '@/modules/library/contexts/LibraryOptionsContext.tsx
import { Mangas } from '@/modules/manga/services/Mangas.ts'; import { Mangas } from '@/modules/manga/services/Mangas.ts';
import { SpecificMangaCardProps } from '@/modules/manga/MangaCard.types.tsx'; import { SpecificMangaCardProps } from '@/modules/manga/MangaCard.types.tsx';
import { TypographyMaxLines } from '@/modules/core/components/TypographyMaxLines.tsx'; import { TypographyMaxLines } from '@/modules/core/components/TypographyMaxLines.tsx';
import { MANGA_COVER_ASPECT_RATIO } from '@/modules/manga/Manga.constants.ts';
const BottomGradient = styled('div')({ const BottomGradient = styled('div')({
position: 'absolute', position: 'absolute',
@@ -92,7 +93,7 @@ export const MangaGridCard = ({
<Card <Card
sx={{ sx={{
// force standard aspect ratio of manga covers // force standard aspect ratio of manga covers
aspectRatio: '225/350', aspectRatio: MANGA_COVER_ASPECT_RATIO,
display: 'flex', display: 'flex',
}} }}
> >

View File

@@ -27,6 +27,7 @@ import { TypographyMaxLines } from '@/modules/core/components/TypographyMaxLines
import { Metadata } from '@/modules/core/components/Metadata.tsx'; import { Metadata } from '@/modules/core/components/Metadata.tsx';
import { MediaQuery } from '@/modules/core/utils/MediaQuery.tsx'; import { MediaQuery } from '@/modules/core/utils/MediaQuery.tsx';
import { TTrackerManga } from '@/modules/tracker/services/Trackers.ts'; import { TTrackerManga } from '@/modules/tracker/services/Trackers.ts';
import { MANGA_COVER_ASPECT_RATIO } from '@/modules/manga/Manga.constants.ts';
const TrackerMangaCardTitle = ({ title, selected }: { title: string; selected: boolean }) => ( const TrackerMangaCardTitle = ({ title, selected }: { title: string; selected: boolean }) => (
<Stack <Stack
@@ -141,7 +142,7 @@ export const TrackerMangaCard = ({
> >
<CardMedia <CardMedia
sx={{ sx={{
aspectRatio: '225/350', aspectRatio: MANGA_COVER_ASPECT_RATIO,
minWidth: '100px', minWidth: '100px',
width: '150px', width: '150px',
borderRadius: 1, borderRadius: 1,