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
|
|
|
|
|
* 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 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';
|
2021-05-27 05:13:01 +04:30
|
|
|
import useLocalStorage from 'util/useLocalStorage';
|
|
|
|
|
import { langCodeToName } from 'util/language';
|
2021-11-14 15:51:08 +05:30
|
|
|
import { Box } from '@mui/system';
|
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', '');
|
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
|
2021-11-14 15:51:08 +05:30
|
|
|
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/`)}
|
|
|
|
|
>
|
2021-11-14 15:51:08 +05:30
|
|
|
<CardContent sx={{
|
|
|
|
|
display: 'flex',
|
|
|
|
|
justifyContent: 'space-between',
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
padding: 2,
|
|
|
|
|
}}
|
|
|
|
|
>
|
2021-09-09 20:43:13 +04:30
|
|
|
|
2021-11-14 15:51:08 +05:30
|
|
|
<Box sx={{ display: 'flex' }}>
|
2021-09-09 22:19:33 +04:30
|
|
|
<Avatar
|
|
|
|
|
variant="rounded"
|
|
|
|
|
alt={name}
|
2021-09-18 20:59:23 +04:30
|
|
|
src={`${serverAddress}${iconUrl}?useCache=${useCache}`}
|
2021-09-09 22:19:33 +04:30
|
|
|
/>
|
2021-11-14 15:51:08 +05: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)}
|
|
|
|
|
</Typography>
|
|
|
|
|
)}
|
2021-11-14 15:51:08 +05:30
|
|
|
</Box>
|
|
|
|
|
</Box>
|
2021-09-09 22:19:33 +04:30
|
|
|
<div>
|
2021-11-14 15:51:08 +05:30
|
|
|
<Box sx={{ display: { xs: 'flex', sm: 'none' } }}>
|
2021-09-09 22:19:33 +04:30
|
|
|
<IconButton
|
2021-11-14 15:51:08 +05:30
|
|
|
sx={{ width: 59, height: 59 }}
|
2021-09-09 22:19:33 +04:30
|
|
|
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
|
|
|
)}
|
2021-11-14 15:51:08 +05:30
|
|
|
</Box>
|
|
|
|
|
<Box sx={{
|
|
|
|
|
display: {
|
|
|
|
|
xs: 'none',
|
|
|
|
|
sm: 'flex',
|
|
|
|
|
},
|
|
|
|
|
'> .MuiButton-root': {
|
|
|
|
|
ml: '20px',
|
|
|
|
|
},
|
|
|
|
|
}}
|
|
|
|
|
>
|
2021-09-09 22:19:33 +04:30
|
|
|
<Button
|
|
|
|
|
variant="outlined"
|
|
|
|
|
onClick={(e) => redirectTo(e, `/sources/${id}/search/`)}
|
|
|
|
|
>
|
|
|
|
|
Search
|
|
|
|
|
</Button>
|
|
|
|
|
{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>
|
2021-11-14 15:51:08 +05:30
|
|
|
</Box>
|
2021-09-09 22:19:33 +04:30
|
|
|
</div>
|
|
|
|
|
</CardContent>
|
2020-12-25 06:36:34 +03:30
|
|
|
</Card>
|
|
|
|
|
);
|
|
|
|
|
}
|