Files
suwayomi-material-you-webui/src/modules/source/components/SourceCard.tsx

137 lines
5.3 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
2021-01-26 23:32:12 +03:30
* 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/.
*/
2021-01-26 23:32:12 +03:30
import CardActionArea from '@mui/material/CardActionArea';
import Avatar from '@mui/material/Avatar';
import Button from '@mui/material/Button';
2021-09-09 17:51:22 +04:30
import Card from '@mui/material/Card';
import CardContent from '@mui/material/CardContent';
import Typography from '@mui/material/Typography';
import React from 'react';
import { useTranslation } from 'react-i18next';
import { Link } from 'react-router-dom';
2024-08-30 21:32:21 +02:00
import Stack from '@mui/material/Stack';
import { requestManager } from '@/lib/requests/RequestManager.ts';
2024-10-05 21:22:12 +02:00
import { SourceContentType } from '@/modules/source/screens/SourceMangas.tsx';
2024-10-05 16:09:34 +02:00
import { SpinnerImage } from '@/modules/core/components/SpinnerImage.tsx';
import { GetSourcesListQuery } from '@/lib/graphql/generated/graphql.ts';
2024-10-05 23:22:42 +02:00
import { MediaQuery } from '@/modules/core/utils/MediaQuery.tsx';
import { translateExtensionLanguage } from '@/modules/extension/Extensions.utils.ts';
2024-12-11 20:10:59 +01:00
import { AppRoutes } from '@/modules/core/AppRoute.constants.ts';
import { MUIUtil } from '@/lib/mui/MUI.util.ts';
2025-04-21 17:45:14 +02:00
import { Sources } from '@/modules/source/services/Sources.ts';
2020-12-25 06:36:34 +03:30
interface IProps {
source: GetSourcesListQuery['sources']['nodes'][number];
showSourceRepo: boolean;
2020-12-25 06:36:34 +03:30
}
2023-10-28 00:32:02 +02:00
export const SourceCard: React.FC<IProps> = (props: IProps) => {
const { t } = useTranslation();
2024-08-30 21:32:21 +02:00
const isMobileWidth = MediaQuery.useIsMobileWidth();
2025-04-21 17:00:13 +02:00
const { source, showSourceRepo } = props;
2020-12-25 06:36:34 +03:30
const {
2025-04-21 17:00:13 +02:00
id,
name,
lang,
iconUrl,
supportsLatest,
isNsfw,
extension: { repo },
} = source;
2020-12-25 06:36:34 +03:30
2025-04-21 17:00:13 +02:00
const sourceName = Sources.isLocalSource(source) ? t('source.local_source.title') : name;
2020-12-25 06:36:34 +03:30
return (
2021-09-09 22:19:33 +04:30
<Card
sx={{
2024-08-30 21:32:21 +02:00
margin: 1,
marginTop: 0,
}}
2021-09-09 22:19:33 +04:30
>
<CardActionArea
component={Link}
2024-12-11 20:10:59 +01:00
to={AppRoutes.sources.childRoutes.browse.path(id)}
state={{ contentType: SourceContentType.POPULAR, clearCache: true }}
>
<CardContent
sx={{
display: 'flex',
alignItems: 'center',
gap: 1,
p: 1.5,
}}
>
<Avatar
variant="rounded"
alt={sourceName}
sx={{
width: 56,
height: 56,
flex: '0 0 auto',
background: 'transparent',
}}
>
<SpinnerImage
spinnerStyle={{ small: true }}
imgStyle={{ objectFit: 'cover', width: '100%', height: '100%' }}
alt={sourceName}
src={requestManager.getValidImgUrlFor(iconUrl)}
/>
</Avatar>
<Stack
sx={{
justifyContent: 'center',
flexGrow: 1,
flexShrink: 1,
wordBreak: 'break-word',
}}
>
<Typography variant="h6" component="h3">
{sourceName}
</Typography>
<Typography variant="caption">
{translateExtensionLanguage(lang)}
{isNsfw && (
<Typography variant="caption" color="error">
{' 18+'}
</Typography>
)}
</Typography>
{showSourceRepo && <Typography variant="caption">{repo}</Typography>}
</Stack>
{supportsLatest && (
<Button
{...MUIUtil.preventRippleProp()}
variant="outlined"
component={Link}
to={AppRoutes.sources.childRoutes.browse.path(id)}
state={{ contentType: SourceContentType.LATEST, clearCache: true }}
>
{t('global.button.latest')}
</Button>
)}
{!isMobileWidth && (
<Button
{...MUIUtil.preventRippleProp()}
variant="outlined"
component={Link}
to={AppRoutes.sources.childRoutes.browse.path(id)}
state={{ contentType: SourceContentType.POPULAR, clearCache: true }}
>
{t('global.button.popular')}
</Button>
)}
</CardContent>
</CardActionArea>
2020-12-25 06:36:34 +03:30
</Card>
);
};