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
|
|
|
|
2022-11-26 13:51:56 +01:00
|
|
|
import { CardActionArea } from '@mui/material';
|
|
|
|
|
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';
|
2021-11-17 15:45:25 +03:30
|
|
|
import { Box, styled } from '@mui/system';
|
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';
|
2022-11-26 13:51:56 +01:00
|
|
|
import { Link, useHistory } from 'react-router-dom';
|
2023-02-24 16:40:37 +01:00
|
|
|
import { ISource } from 'typings';
|
2023-04-21 00:27:42 +02:00
|
|
|
import { translateExtensionLanguage } from 'screens/util/Extensions';
|
2023-05-18 13:25:19 +02:00
|
|
|
import requestManager from 'lib/RequestManager';
|
2021-11-15 17:21:31 +03:30
|
|
|
|
2021-11-17 15:45:25 +03:30
|
|
|
const MobileWidthButtons = styled('div')(({ theme }) => ({
|
|
|
|
|
display: 'flex',
|
|
|
|
|
[theme.breakpoints.up('sm')]: {
|
|
|
|
|
display: 'none',
|
2021-11-15 17:21:31 +03:30
|
|
|
},
|
2021-11-17 15:45:25 +03:30
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
const WiderWidthButtons = styled('div')(({ theme }) => ({
|
|
|
|
|
display: 'flex',
|
|
|
|
|
[theme.breakpoints.down('sm')]: {
|
|
|
|
|
display: 'none',
|
2021-11-15 17:21:31 +03:30
|
|
|
},
|
2021-11-17 15:45:25 +03:30
|
|
|
|
|
|
|
|
'& .MuiButton-root': {
|
|
|
|
|
marginLeft: '20px',
|
2021-11-15 17:21:31 +03:30
|
|
|
},
|
|
|
|
|
}));
|
2020-12-25 06:36:34 +03:30
|
|
|
|
|
|
|
|
interface IProps {
|
2023-02-06 10:06:33 +01:00
|
|
|
source: ISource;
|
2020-12-25 06:36:34 +03:30
|
|
|
}
|
|
|
|
|
|
2022-11-26 13:51:56 +01:00
|
|
|
const SourceCard: React.FC<IProps> = (props: IProps) => {
|
2023-03-23 13:59:32 +01:00
|
|
|
const { t } = useTranslation();
|
|
|
|
|
|
2020-12-25 06:36:34 +03:30
|
|
|
const {
|
2023-02-06 10:06:33 +01:00
|
|
|
source: { id, name, lang, iconUrl, supportsLatest, isNsfw },
|
2020-12-25 06:36:34 +03:30
|
|
|
} = props;
|
|
|
|
|
|
2021-09-09 20:43:13 +04:30
|
|
|
const history = useHistory();
|
|
|
|
|
|
2021-09-09 22:19:33 +04:30
|
|
|
const redirectTo = (e: any, to: string) => {
|
|
|
|
|
history.push(to);
|
|
|
|
|
|
|
|
|
|
// prevent parent tags from getting the event
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
};
|
|
|
|
|
|
2020-12-25 06:36:34 +03:30
|
|
|
return (
|
2021-09-09 22:19:33 +04:30
|
|
|
<Card
|
2021-11-17 15:45:25 +03:30
|
|
|
sx={{
|
|
|
|
|
margin: '10px',
|
|
|
|
|
}}
|
2021-09-09 22:19:33 +04:30
|
|
|
>
|
2023-02-06 10:06:33 +01:00
|
|
|
<CardActionArea component={Link} to={`/sources/${id}/popular/`}>
|
2022-11-26 13:51:56 +01:00
|
|
|
<CardContent
|
|
|
|
|
sx={{
|
|
|
|
|
display: 'flex',
|
|
|
|
|
justifyContent: 'space-between',
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
padding: 2,
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Box sx={{ display: 'flex' }}>
|
|
|
|
|
<Avatar
|
|
|
|
|
variant="rounded"
|
|
|
|
|
alt={name}
|
|
|
|
|
sx={{
|
|
|
|
|
width: 56,
|
|
|
|
|
height: 56,
|
|
|
|
|
flex: '0 0 auto',
|
|
|
|
|
mr: 2,
|
|
|
|
|
}}
|
2023-05-18 13:25:19 +02:00
|
|
|
src={requestManager.getValidImgUrlFor(iconUrl)}
|
2022-11-26 13:51:56 +01:00
|
|
|
/>
|
2023-02-06 10:06:33 +01:00
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
display: 'flex',
|
|
|
|
|
flexDirection: 'column',
|
|
|
|
|
justifyContent: 'center',
|
|
|
|
|
}}
|
|
|
|
|
>
|
2022-11-26 13:51:56 +01:00
|
|
|
<Typography variant="h5" component="h2">
|
|
|
|
|
{name}
|
2021-09-19 17:11:29 +04:30
|
|
|
</Typography>
|
2022-11-26 13:51:56 +01:00
|
|
|
{id !== '0' && (
|
|
|
|
|
<Typography variant="caption" display="block" gutterBottom>
|
2023-04-21 00:27:42 +02:00
|
|
|
{translateExtensionLanguage(lang)}
|
2022-11-26 13:51:56 +01:00
|
|
|
{isNsfw && (
|
2023-02-08 18:19:26 +01:00
|
|
|
<Typography variant="caption" display="inline" gutterBottom color="red">
|
2022-11-26 13:51:56 +01:00
|
|
|
{' 18+'}
|
|
|
|
|
</Typography>
|
|
|
|
|
)}
|
|
|
|
|
</Typography>
|
|
|
|
|
)}
|
|
|
|
|
</Box>
|
2021-11-17 15:45:25 +03:30
|
|
|
</Box>
|
2022-11-26 13:51:56 +01:00
|
|
|
<>
|
|
|
|
|
<MobileWidthButtons>
|
|
|
|
|
{supportsLatest && (
|
2023-02-08 18:19:26 +01:00
|
|
|
<Button variant="outlined" onClick={(e) => redirectTo(e, `/sources/${id}/latest/`)}>
|
2023-03-23 13:59:32 +01:00
|
|
|
{t('global.button.latest')}
|
2022-11-26 13:51:56 +01:00
|
|
|
</Button>
|
|
|
|
|
)}
|
|
|
|
|
</MobileWidthButtons>
|
|
|
|
|
<WiderWidthButtons>
|
|
|
|
|
{supportsLatest && (
|
2023-02-08 18:19:26 +01:00
|
|
|
<Button component={Link} to={`/sources/${id}/latest/`} variant="outlined">
|
2023-03-23 13:59:32 +01:00
|
|
|
{t('global.button.latest')}
|
2022-11-26 13:51:56 +01:00
|
|
|
</Button>
|
|
|
|
|
)}
|
2023-02-08 18:19:26 +01:00
|
|
|
<Button component={Link} to={`/sources/${id}/popular/`} variant="outlined">
|
2023-03-23 13:59:32 +01:00
|
|
|
{t('global.button.browse')}
|
2021-09-09 20:43:13 +04:30
|
|
|
</Button>
|
2022-11-26 13:51:56 +01:00
|
|
|
</WiderWidthButtons>
|
|
|
|
|
</>
|
|
|
|
|
</CardContent>
|
|
|
|
|
</CardActionArea>
|
2020-12-25 06:36:34 +03:30
|
|
|
</Card>
|
|
|
|
|
);
|
2022-11-26 13:51:56 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default SourceCard;
|