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

171 lines
5.6 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 makeStyles from '@mui/styles/makeStyles';
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 20:43:13 +04:30
import SearchIcon from '@mui/icons-material/Search';
2021-09-09 17:51:22 +04:30
import Button from '@mui/material/Button';
2021-09-09 20:43:13 +04:30
import IconButton from '@mui/material/IconButton';
import FiberNewOutlinedIcon from '@mui/icons-material/FiberNewOutlined';
2021-09-09 17:51:22 +04:30
import Avatar from '@mui/material/Avatar';
import Typography from '@mui/material/Typography';
import useLocalStorage from 'util/useLocalStorage';
import { langCodeToName } from 'util/language';
2020-12-25 06:36:34 +03:30
const useStyles = makeStyles((theme) => ({
root: {
display: 'flex',
justifyContent: 'space-between',
alignItems: 'center',
padding: 16,
},
bullet: {
display: 'inline-block',
margin: '0 2px',
transform: 'scale(0.8)',
},
title: {
fontSize: 14,
},
pos: {
marginBottom: 12,
},
icon: {
width: theme.spacing(7),
height: theme.spacing(7),
flex: '0 0 auto',
marginRight: 16,
},
card: {
margin: '10px',
2021-09-09 20:43:13 +04:30
'&:hover': {
backgroundColor: theme.palette.action.hover,
transition: 'background-color 100ms cubic-bezier(0.4, 0, 0.2, 1) 0ms',
2021-09-09 20:43:13 +04:30
},
'&:active': {
backgroundColor: theme.palette.action.selected,
transition: 'background-color 100ms cubic-bezier(0.4, 0, 0.2, 1) 0ms',
2021-09-09 20:43:13 +04:30
},
},
showMobile: {
display: 'flex',
[theme.breakpoints.up('sm')]: {
display: 'none',
},
},
showBigger: {
display: 'flex',
[theme.breakpoints.down('sm')]: {
display: 'none',
},
},
2020-12-25 06:36:34 +03:30
}));
interface IProps {
source: ISource
}
export default function SourceCard(props: IProps) {
const {
source: {
2021-09-09 22:19:33 +04:30
id, name, lang, iconUrl, supportsLatest,
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', '');
2020-12-25 06:36:34 +03:30
const classes = useStyles();
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
className={classes.card}
onClick={(e) => redirectTo(e, `/sources/${id}/popular/`)}
>
<CardContent className={classes.root}>
2021-09-09 20:43:13 +04:30
2021-09-09 22:19:33 +04:30
<div style={{ display: 'flex' }}>
<Avatar
variant="rounded"
className={classes.icon}
alt={name}
src={serverAddress + iconUrl}
/>
<div style={{ display: 'flex', flexDirection: 'column' }}>
<Typography variant="h5" component="h2">
{name}
</Typography>
<Typography variant="caption" display="block" gutterBottom>
{langCodeToName(lang)}
</Typography>
2021-09-09 20:43:13 +04:30
</div>
2021-09-09 22:19:33 +04:30
</div>
<div>
<div className={classes.showMobile}>
<IconButton
style={{ width: 59, height: 59 }}
onClick={(e) => redirectTo(e, `/sources/${id}/search/`)}
size="large"
edge="end"
>
<SearchIcon
fontSize="medium"
/>
</IconButton>
{supportsLatest && (
2021-09-09 20:43:13 +04:30
<IconButton
2021-09-09 22:19:33 +04:30
onClick={(e) => redirectTo(e, `/sources/${id}/latest/`)}
2021-09-09 20:43:13 +04:30
size="large"
>
2021-09-09 22:19:33 +04:30
<FiberNewOutlinedIcon
fontSize="large"
2021-09-09 20:43:13 +04:30
/>
</IconButton>
2021-09-09 22:19:33 +04:30
)}
</div>
<div className={classes.showBigger}>
<Button
variant="outlined"
style={{ marginLeft: 20 }}
onClick={(e) => redirectTo(e, `/sources/${id}/search/`)}
>
Search
</Button>
{supportsLatest && (
2021-09-09 20:43:13 +04:30
<Button
variant="outlined"
style={{ marginLeft: 20 }}
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"
style={{ marginLeft: 20 }}
onClick={(e: any) => redirectTo(e, `/sources/${id}/popular/`)}
>
Browse
</Button>
2020-12-25 06:36:34 +03:30
</div>
2021-09-09 22:19:33 +04:30
</div>
</CardContent>
2020-12-25 06:36:34 +03:30
</Card>
);
}