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

136 lines
4.8 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';
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 { Box, styled } from '@mui/system';
import React from 'react';
import { useTranslation } from 'react-i18next';
import { Link, useHistory } from 'react-router-dom';
import { ISource } from 'typings';
import { translateExtensionLanguage } from 'screens/util/Extensions';
import requestManager from 'lib/RequestManager';
const MobileWidthButtons = styled('div')(({ theme }) => ({
display: 'flex',
[theme.breakpoints.up('sm')]: {
display: 'none',
},
}));
const WiderWidthButtons = styled('div')(({ theme }) => ({
display: 'flex',
[theme.breakpoints.down('sm')]: {
display: 'none',
},
'& .MuiButton-root': {
marginLeft: '20px',
},
}));
2020-12-25 06:36:34 +03:30
interface IProps {
source: ISource;
2020-12-25 06:36:34 +03:30
}
const SourceCard: React.FC<IProps> = (props: IProps) => {
const { t } = useTranslation();
2020-12-25 06:36:34 +03:30
const {
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
sx={{
margin: '10px',
}}
2021-09-09 22:19:33 +04:30
>
<CardActionArea component={Link} to={`/sources/${id}/popular/`}>
<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,
}}
src={requestManager.getValidImgUrlFor(iconUrl)}
/>
<Box
sx={{
display: 'flex',
flexDirection: 'column',
justifyContent: 'center',
}}
>
<Typography variant="h5" component="h2">
{name}
2021-09-19 17:11:29 +04:30
</Typography>
{id !== '0' && (
<Typography variant="caption" display="block" gutterBottom>
{translateExtensionLanguage(lang)}
{isNsfw && (
<Typography variant="caption" display="inline" gutterBottom color="red">
{' 18+'}
</Typography>
)}
</Typography>
)}
</Box>
</Box>
<>
<MobileWidthButtons>
{supportsLatest && (
<Button variant="outlined" onClick={(e) => redirectTo(e, `/sources/${id}/latest/`)}>
{t('global.button.latest')}
</Button>
)}
</MobileWidthButtons>
<WiderWidthButtons>
{supportsLatest && (
<Button component={Link} to={`/sources/${id}/latest/`} variant="outlined">
{t('global.button.latest')}
</Button>
)}
<Button component={Link} to={`/sources/${id}/popular/`} variant="outlined">
{t('global.button.browse')}
2021-09-09 20:43:13 +04:30
</Button>
</WiderWidthButtons>
</>
</CardContent>
</CardActionArea>
2020-12-25 06:36:34 +03:30
</Card>
);
};
export default SourceCard;