diff --git a/src/modules/manga/Manga.constants.ts b/src/modules/manga/Manga.constants.ts new file mode 100644 index 00000000..cf0aa746 --- /dev/null +++ b/src/modules/manga/Manga.constants.ts @@ -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'; diff --git a/src/modules/manga/components/MangaDetails.tsx b/src/modules/manga/components/MangaDetails.tsx index b0c03c97..921cdd82 100644 --- a/src/modules/manga/components/MangaDetails.tsx +++ b/src/modules/manga/components/MangaDetails.tsx @@ -44,6 +44,7 @@ import { useLocalStorage } from '@/modules/core/hooks/useStorage.tsx'; import { useResizeObserver } from '@/modules/core/hooks/useResizeObserver.tsx'; import { useMetadataServerSettings } from '@/modules/settings/services/ServerSettingsMetadata.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 }) => ({ display: 'flex', @@ -141,15 +142,7 @@ const Thumbnail = ({ manga }: { manga: Partial }) => { const popupState = usePopupState({ variant: 'popover', popupId: 'manga-thumbnail-fullscreen' }); - const [imageHeight, setImageHeight] = useState(); - const [imageElement, setImageElement] = useState(null); - useResizeObserver( - imageElement, - useCallback(() => setImageHeight(imageElement?.clientHeight), [imageElement]), - ); - const [isImageReady, setIsImageReady] = useState(false); - const isImageHeightReady = isImageReady && !!imageHeight; return ( <> @@ -160,23 +153,23 @@ const Thumbnail = ({ manga }: { manga: Partial }) => { overflow: 'hidden', backgroundColor: 'background.paper', width: '150px', - height: `${isImageHeightReady ? imageHeight : 225}px`, + maxHeight: 'fit-content', + aspectRatio: MANGA_COVER_ASPECT_RATIO, flexShrink: 0, + flexGrow: 0, [theme.breakpoints.up('lg')]: { width: '200px', - height: `${isImageHeightReady ? imageHeight : 300}px`, }, [theme.breakpoints.up('xl')]: { width: '300px', - height: `${isImageHeightReady ? imageHeight : 450}px`, }, }} > setIsImageReady(true)} + imgStyle={{ width: '100%', height: '100%', objectFit: 'cover' }} /> {isImageReady && ( }) => { popupState.close()} - sx={{ height: '100vh', py: 2, outline: 0, justifyContent: 'center', alignItems: 'center' }} + sx={{ height: '100vh', p: 2, outline: 0, justifyContent: 'center', alignItems: 'center' }} > diff --git a/src/modules/tracker/components/cards/TrackerMangaCard.tsx b/src/modules/tracker/components/cards/TrackerMangaCard.tsx index a0fa676e..5a086ac4 100644 --- a/src/modules/tracker/components/cards/TrackerMangaCard.tsx +++ b/src/modules/tracker/components/cards/TrackerMangaCard.tsx @@ -27,6 +27,7 @@ import { TypographyMaxLines } from '@/modules/core/components/TypographyMaxLines import { Metadata } from '@/modules/core/components/Metadata.tsx'; import { MediaQuery } from '@/modules/core/utils/MediaQuery.tsx'; 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 }) => (