tachiyomi-extensions-inspector/webUI/react/src/components/SourceCard.tsx

84 lines
2.8 KiB
TypeScript
Raw Normal View History

2021-01-26 21:02:12 +01:00
/* This Source Code Form is subject to the terms of the Mozilla Public
* 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 04:06:34 +01:00
import React from 'react';
import { makeStyles } from '@material-ui/core/styles';
import Card from '@material-ui/core/Card';
import CardContent from '@material-ui/core/CardContent';
import Button from '@material-ui/core/Button';
import Avatar from '@material-ui/core/Avatar';
import Typography from '@material-ui/core/Typography';
2021-03-07 20:05:27 +01:00
import useLocalStorage from '../util/useLocalStorage';
2021-03-09 14:14:09 +01:00
import { langCodeToName } from '../util/language';
2020-12-25 04:06:34 +01:00
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,
},
}));
interface IProps {
source: ISource
}
export default function SourceCard(props: IProps) {
const {
source: {
2020-12-25 19:44:54 +01:00
id, name, lang, iconUrl, supportsLatest,
2020-12-25 04:06:34 +01:00
},
} = props;
2021-03-07 20:05:27 +01:00
const [serverAddress] = useLocalStorage<String>('serverBaseURL', '');
2020-12-25 04:06:34 +01:00
const classes = useStyles();
return (
<Card>
<CardContent className={classes.root}>
<div style={{ display: 'flex' }}>
<Avatar
variant="rounded"
className={classes.icon}
alt={name}
2021-03-07 20:05:27 +01:00
src={serverAddress + iconUrl}
2020-12-25 04:06:34 +01:00
/>
<div style={{ display: 'flex', flexDirection: 'column' }}>
<Typography variant="h5" component="h2">
{name}
</Typography>
<Typography variant="caption" display="block" gutterBottom>
2021-03-09 14:14:09 +01:00
{langCodeToName(lang)}
2020-12-25 04:06:34 +01:00
</Typography>
</div>
</div>
<div style={{ display: 'flex' }}>
2021-01-22 15:37:31 +01:00
<Button variant="outlined" style={{ marginLeft: 20 }} onClick={() => { window.location.href = `/sources/${id}/search/`; }}>Search</Button>
{supportsLatest && <Button variant="outlined" style={{ marginLeft: 20 }} onClick={() => { window.location.href = `/sources/${id}/latest/`; }}>Latest</Button>}
<Button variant="outlined" style={{ marginLeft: 20 }} onClick={() => { window.location.href = `/sources/${id}/popular/`; }}>Browse</Button>
2020-12-25 04:06:34 +01:00
</div>
</CardContent>
</Card>
);
}