2021-03-26 04:17:02 +04:30
|
|
|
/*
|
|
|
|
|
* 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
|
2023-05-18 13:17:41 +02:00
|
|
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
|
|
|
*/
|
2021-01-26 23:32:12 +03:30
|
|
|
|
2024-04-14 15:50:12 +02:00
|
|
|
import CardActionArea from '@mui/material/CardActionArea';
|
2022-11-26 13:51:56 +01:00
|
|
|
import Button from '@mui/material/Button';
|
2021-09-09 17:51:22 +04:30
|
|
|
import Card from '@mui/material/Card';
|
|
|
|
|
import Typography from '@mui/material/Typography';
|
2022-11-26 13:51:56 +01:00
|
|
|
import React from 'react';
|
2023-03-23 13:59:32 +01:00
|
|
|
import { useTranslation } from 'react-i18next';
|
2023-05-28 12:16:06 +02:00
|
|
|
import { Link } from 'react-router-dom';
|
2024-08-30 21:32:21 +02:00
|
|
|
import Stack from '@mui/material/Stack';
|
2025-05-17 22:17:15 +02:00
|
|
|
import PushPinIcon from '@mui/icons-material/PushPin';
|
|
|
|
|
import PushPinOutlinedIcon from '@mui/icons-material/PushPinOutlined';
|
|
|
|
|
import IconButton from '@mui/material/IconButton';
|
2024-10-06 01:27:51 +02:00
|
|
|
import { requestManager } from '@/lib/requests/RequestManager.ts';
|
2024-10-05 21:22:12 +02:00
|
|
|
import { SourceContentType } from '@/modules/source/screens/SourceMangas.tsx';
|
2024-07-03 23:15:50 +02:00
|
|
|
import { GetSourcesListQuery } from '@/lib/graphql/generated/graphql.ts';
|
2024-12-11 20:10:59 +01:00
|
|
|
import { AppRoutes } from '@/modules/core/AppRoute.constants.ts';
|
2025-03-29 03:12:36 +01:00
|
|
|
import { MUIUtil } from '@/lib/mui/MUI.util.ts';
|
2025-04-21 17:45:14 +02:00
|
|
|
import { Sources } from '@/modules/source/services/Sources.ts';
|
2025-05-03 12:14:05 +02:00
|
|
|
import { ListCardAvatar } from '@/modules/core/components/lists/cards/ListCardAvatar.tsx';
|
|
|
|
|
import { ListCardContent } from '@/modules/core/components/lists/cards/ListCardContent.tsx';
|
2025-05-17 22:17:15 +02:00
|
|
|
import { CustomTooltip } from '@/modules/core/components/CustomTooltip.tsx';
|
|
|
|
|
import { createUpdateSourceMetadata, useGetSourceMetadata } from '@/modules/source/services/SourceMetadata.ts';
|
|
|
|
|
import { makeToast } from '@/modules/core/utils/Toast.ts';
|
|
|
|
|
import { getErrorMessage } from '@/lib/HelperFunctions.ts';
|
2025-06-23 00:41:47 +02:00
|
|
|
import { languageCodeToName } from '@/modules/core/utils/Languages.ts';
|
2020-12-25 06:36:34 +03:30
|
|
|
|
|
|
|
|
interface IProps {
|
2024-07-03 23:15:50 +02:00
|
|
|
source: GetSourcesListQuery['sources']['nodes'][number];
|
2024-01-09 22:09:31 +01:00
|
|
|
showSourceRepo: boolean;
|
2025-06-23 00:41:47 +02:00
|
|
|
showLanguage: 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) => {
|
2023-03-23 13:59:32 +01:00
|
|
|
const { t } = useTranslation();
|
|
|
|
|
|
2025-06-23 00:41:47 +02:00
|
|
|
const { source, showSourceRepo, showLanguage } = 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-05-17 22:17:15 +02:00
|
|
|
const { isPinned } = useGetSourceMetadata(source);
|
|
|
|
|
|
2025-04-21 17:00:13 +02:00
|
|
|
const sourceName = Sources.isLocalSource(source) ? t('source.local_source.title') : name;
|
2024-09-29 15:19:06 +02:00
|
|
|
|
2025-05-17 22:17:15 +02:00
|
|
|
const updateSetting = createUpdateSourceMetadata(source, (e) =>
|
|
|
|
|
makeToast(t('global.error.label.failed_to_save_changes'), 'error', getErrorMessage(e)),
|
|
|
|
|
);
|
|
|
|
|
|
2020-12-25 06:36:34 +03:30
|
|
|
return (
|
2025-06-23 00:36:32 +02:00
|
|
|
<Card>
|
2023-11-11 23:43:22 +01:00
|
|
|
<CardActionArea
|
|
|
|
|
component={Link}
|
2024-12-11 20:10:59 +01:00
|
|
|
to={AppRoutes.sources.childRoutes.browse.path(id)}
|
2023-11-11 23:43:22 +01:00
|
|
|
state={{ contentType: SourceContentType.POPULAR, clearCache: true }}
|
|
|
|
|
>
|
2025-04-25 01:05:43 +02:00
|
|
|
<ListCardContent>
|
2025-04-25 00:50:51 +02:00
|
|
|
<ListCardAvatar iconUrl={requestManager.getValidImgUrlFor(iconUrl)} alt={sourceName} />
|
2025-04-25 00:27:28 +02:00
|
|
|
<Stack
|
|
|
|
|
sx={{
|
|
|
|
|
justifyContent: 'center',
|
|
|
|
|
flexGrow: 1,
|
|
|
|
|
flexShrink: 1,
|
|
|
|
|
wordBreak: 'break-word',
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Typography variant="h6" component="h3">
|
|
|
|
|
{sourceName}
|
|
|
|
|
</Typography>
|
|
|
|
|
<Typography variant="caption">
|
2025-06-23 00:41:47 +02:00
|
|
|
{showLanguage && languageCodeToName(lang)}
|
2025-04-25 00:27:28 +02:00
|
|
|
{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 }}
|
2024-03-08 00:24:01 +01:00
|
|
|
>
|
2025-04-25 00:27:28 +02:00
|
|
|
{t('global.button.latest')}
|
|
|
|
|
</Button>
|
|
|
|
|
)}
|
2025-05-17 22:17:15 +02:00
|
|
|
<CustomTooltip title={t(isPinned ? 'source.pin.remove' : 'source.pin.add')}>
|
|
|
|
|
<IconButton
|
|
|
|
|
{...MUIUtil.preventRippleProp()}
|
|
|
|
|
onClick={(e) => {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
updateSetting('isPinned', !isPinned);
|
|
|
|
|
}}
|
|
|
|
|
color={isPinned ? 'primary' : 'inherit'}
|
|
|
|
|
>
|
|
|
|
|
{isPinned ? <PushPinIcon /> : <PushPinOutlinedIcon />}
|
|
|
|
|
</IconButton>
|
|
|
|
|
</CustomTooltip>
|
2025-04-25 01:05:43 +02:00
|
|
|
</ListCardContent>
|
2022-11-26 13:51:56 +01:00
|
|
|
</CardActionArea>
|
2020-12-25 06:36:34 +03:30
|
|
|
</Card>
|
|
|
|
|
);
|
2022-11-26 13:51:56 +01:00
|
|
|
};
|