Files
suwayomi-material-you-webui/src/features/manga/components/cards/MangaListCard.tsx

126 lines
5.1 KiB
TypeScript
Raw Normal View History

/*
* 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/.
*/
import Card from '@mui/material/Card';
import CardActionArea from '@mui/material/CardActionArea';
import Box from '@mui/material/Box';
import Stack from '@mui/material/Stack';
import { Link as RouterLink } from 'react-router-dom';
2025-01-13 01:29:40 +01:00
import { memo, useRef } from 'react';
import { CustomTooltip } from '@/base/components/CustomTooltip.tsx';
import { TypographyMaxLines } from '@/base/components/texts/TypographyMaxLines.tsx';
2025-08-15 22:02:58 +02:00
import { SpecificMangaCardProps } from '@/features/manga/Manga.types.ts';
import { Mangas } from '@/features/manga/services/Mangas.ts';
import { MangaOptionButton } from '@/features/manga/components/MangaOptionButton.tsx';
import { ListCardAvatar } from '@/base/components/lists/cards/ListCardAvatar.tsx';
import { ListCardContent } from '@/base/components/lists/cards/ListCardContent';
import { MediaQuery } from '@/base/utils/MediaQuery.tsx';
2025-01-13 01:29:40 +01:00
export const MangaListCard = memo(
({
manga,
longPressBind,
popupState,
handleClick,
mangaLinkTo,
selected,
inLibraryIndicator,
isInLibrary,
handleSelection,
continueReadingButton,
mangaBadges,
mode,
}: SpecificMangaCardProps) => {
2025-06-10 22:09:02 +02:00
const preventMobileContextMenu = MediaQuery.usePreventMobileContextMenu();
2025-01-13 01:29:40 +01:00
const optionButtonRef = useRef<HTMLButtonElement>(null);
2025-01-13 01:29:40 +01:00
const { id, title } = manga;
2025-01-13 01:29:40 +01:00
return (
<Card>
<CardActionArea
component={RouterLink}
to={mangaLinkTo}
state={Mangas.createLocationState(manga, mode)}
2025-01-13 01:29:40 +01:00
onClick={handleClick}
{...longPressBind(() => popupState.open(optionButtonRef.current))}
2025-06-10 22:09:02 +02:00
onContextMenu={preventMobileContextMenu}
sx={{
2025-06-10 22:09:02 +02:00
...MediaQuery.preventMobileContextMenuSx(),
2025-01-13 01:29:40 +01:00
'@media (hover: hover) and (pointer: fine)': {
'&:hover .manga-option-button': {
visibility: 'visible',
pointerEvents: 'all',
},
'&:hover .source-manga-library-state-button': {
display: 'inline-flex',
},
'&:hover .source-manga-library-state-indicator': {
display: mode === 'source' ? 'none' : 'inline-flex',
},
},
}}
>
2025-04-25 01:05:43 +02:00
<ListCardContent
sx={{
2025-01-13 01:29:40 +01:00
justifyContent: 'space-between',
position: 'relative',
2024-09-03 17:15:47 +02:00
}}
>
2025-04-25 00:50:51 +02:00
<ListCardAvatar
iconUrl={Mangas.getThumbnailUrl(manga)}
alt={manga.title}
slots={{
spinnerImageProps: {
imgStyle: {
imageRendering: 'pixelated',
filter: inLibraryIndicator && isInLibrary ? 'brightness(0.4)' : undefined,
},
},
2025-01-13 01:29:40 +01:00
}}
2025-04-25 00:50:51 +02:00
/>
2025-01-13 01:29:40 +01:00
<Box
sx={{
display: 'flex',
flexDirection: 'row',
flexGrow: 1,
width: 'min-content',
}}
>
<CustomTooltip title={title} placement="top">
2025-01-13 01:29:40 +01:00
<TypographyMaxLines variant="h6" component="h3">
{title}
</TypographyMaxLines>
</CustomTooltip>
2025-01-13 01:29:40 +01:00
</Box>
<Stack
direction="row"
sx={{
alignItems: 'center',
gap: 0.5,
}}
>
{mangaBadges}
{continueReadingButton}
<MangaOptionButton
ref={optionButtonRef}
popupState={popupState}
id={id}
selected={selected}
handleSelection={handleSelection}
asCheckbox
/>
</Stack>
2025-04-25 01:05:43 +02:00
</ListCardContent>
2025-01-13 01:29:40 +01:00
</CardActionArea>
</Card>
);
},
);