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

143 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/. */
2020-12-25 06:36:34 +03:30
import React from 'react';
2021-09-09 17:51:22 +04:30
import Card from '@mui/material/Card';
import CardContent from '@mui/material/CardContent';
2021-09-09 22:19:33 +04:30
import { useHistory } from 'react-router-dom';
2021-09-09 17:51:22 +04:30
import Button from '@mui/material/Button';
import Avatar from '@mui/material/Avatar';
import Typography from '@mui/material/Typography';
import useLocalStorage from 'util/useLocalStorage';
import { langCodeToName } from 'util/language';
import { Box, styled } from '@mui/system';
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
}
export default function SourceCard(props: IProps) {
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-03-07 22:35:27 +03:30
const [serverAddress] = useLocalStorage<String>('serverBaseURL', '');
2021-09-18 20:59:23 +04:30
const [useCache] = useLocalStorage<boolean>('useCache', true);
2021-03-07 22:35:27 +03:30
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',
'&:hover': {
backgroundColor: 'action.hover',
transition: 'background-color 100ms cubic-bezier(0.4, 0, 0.2, 1) 0ms',
},
'&:active': {
backgroundColor: 'action.selected',
transition: 'background-color 100ms cubic-bezier(0.4, 0, 0.2, 1) 0ms',
},
}}
2021-09-09 22:19:33 +04:30
onClick={(e) => redirectTo(e, `/sources/${id}/popular/`)}
>
<CardContent sx={{
display: 'flex',
justifyContent: 'space-between',
alignItems: 'center',
padding: 2,
}}
>
2021-09-09 20:43:13 +04:30
<Box sx={{ display: 'flex' }}>
2021-09-09 22:19:33 +04:30
<Avatar
variant="rounded"
alt={name}
sx={{
width: 56,
height: 56,
flex: '0 0 auto',
mr: 2,
}}
2021-09-18 20:59:23 +04:30
src={`${serverAddress}${iconUrl}?useCache=${useCache}`}
2021-09-09 22:19:33 +04:30
/>
<Box sx={{ display: 'flex', flexDirection: 'column', justifyContent: 'center' }}>
2021-09-09 22:19:33 +04:30
<Typography variant="h5" component="h2">
{name}
</Typography>
2021-09-19 17:11:29 +04:30
{id !== '0' && (
<Typography variant="caption" display="block" gutterBottom>
{langCodeToName(lang)}
{isNsfw && (
<Typography variant="caption" display="inline" gutterBottom color="red">
{' 18+'}
</Typography>
)}
2021-09-19 17:11:29 +04:30
</Typography>
)}
</Box>
</Box>
<>
<MobileWidthButtons>
2021-09-09 22:19:33 +04:30
{supportsLatest && (
<Button
variant="outlined"
2021-09-09 22:19:33 +04:30
onClick={(e) => redirectTo(e, `/sources/${id}/latest/`)}
2021-09-09 20:43:13 +04:30
>
Latest
</Button>
2021-09-09 22:19:33 +04:30
)}
</MobileWidthButtons>
<WiderWidthButtons>
2021-09-09 22:19:33 +04:30
{supportsLatest && (
2021-09-09 20:43:13 +04:30
<Button
variant="outlined"
2021-09-09 22:19:33 +04:30
onClick={(e) => redirectTo(e, `/sources/${id}/latest/`)}
2021-09-09 20:43:13 +04:30
>
2021-09-09 22:19:33 +04:30
Latest
2021-09-09 20:43:13 +04:30
</Button>
2021-09-09 22:19:33 +04:30
)}
<Button
variant="outlined"
onClick={(e: any) => redirectTo(e, `/sources/${id}/popular/`)}
>
Browse
</Button>
</WiderWidthButtons>
</>
2021-09-09 22:19:33 +04:30
</CardContent>
2020-12-25 06:36:34 +03:30
</Card>
);
}