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

150 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/. */
2021-01-19 20:20:28 +03:30
import React from 'react';
import { makeStyles, useTheme } from '@material-ui/core/styles';
2021-01-19 20:20:28 +03:30
import Card from '@material-ui/core/Card';
import CardContent from '@material-ui/core/CardContent';
import IconButton from '@material-ui/core/IconButton';
import MoreVertIcon from '@material-ui/icons/MoreVert';
2021-01-19 20:20:28 +03:30
import Typography from '@material-ui/core/Typography';
import { Link } from 'react-router-dom';
import Menu from '@material-ui/core/Menu';
import MenuItem from '@material-ui/core/MenuItem';
2021-05-14 19:22:10 +04:30
import BookmarkIcon from '@material-ui/icons/Bookmark';
import client from 'util/client';
2021-01-19 20:20:28 +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-01-19 20:20:28 +03:30
}));
2021-01-19 21:02:57 +03:30
interface IProps{
chapter: IChapter
triggerChaptersUpdate: () => void
2021-05-30 04:01:49 +04:30
downloadingString: string
2021-01-19 21:02:57 +03:30
}
export default function ChapterCard(props: IProps) {
2021-01-19 20:20:28 +03:30
const classes = useStyles();
const theme = useTheme();
2021-05-30 04:01:49 +04:30
const { chapter, triggerChaptersUpdate, downloadingString } = props;
2021-01-19 20:20:28 +03:30
2021-05-11 18:45:53 +04:30
const dateStr = chapter.uploadDate && new Date(chapter.uploadDate).toISOString().slice(0, 10);
2021-01-20 00:04:12 +03:30
const [anchorEl, setAnchorEl] = React.useState<null | HTMLElement>(null);
const handleClick = (event: React.MouseEvent<HTMLButtonElement>) => {
setAnchorEl(event.currentTarget);
};
const handleClose = () => {
setAnchorEl(null);
};
2021-05-14 17:31:07 +04:30
const sendChange = (key: string, value: any) => {
handleClose();
const formData = new FormData();
formData.append(key, value);
client.patch(`/api/v1/manga/${chapter.mangaId}/chapter/${chapter.index}`, formData)
.then(() => triggerChaptersUpdate());
2021-05-14 17:31:07 +04:30
};
2021-05-30 04:01:49 +04:30
const downloadChapter = () => {
client.get(`/api/v1/download/${chapter.mangaId}/chapter/${chapter.index}`);
handleClose();
};
2021-05-19 16:50:48 +04:30
const readChapterColor = theme.palette.type === 'dark' ? '#acacac' : '#b0b0b0';
2021-01-19 20:20:28 +03:30
return (
<>
<li>
<Card className={classes.card}>
2021-05-19 16:50:48 +04:30
<CardContent className={classes.root}>
2021-03-23 03:50:55 +04:30
<Link
2021-05-14 17:31:07 +04:30
to={`/manga/${chapter.mangaId}/chapter/${chapter.index}`}
style={{
textDecoration: 'none',
2021-05-19 16:50:48 +04:30
color: chapter.read ? readChapterColor : theme.palette.text.primary,
}}
2021-03-23 03:50:55 +04:30
>
<div style={{ display: 'flex' }}>
<div style={{ display: 'flex', flexDirection: 'column' }}>
<Typography variant="h5" component="h2">
2021-05-14 19:22:10 +04:30
<span style={{ color: theme.palette.primary.dark }}>
{chapter.bookmarked && <BookmarkIcon />}
</span>
{chapter.name}
{chapter.chapterNumber > 0 && ` : ${chapter.chapterNumber}`}
</Typography>
<Typography variant="caption" display="block" gutterBottom>
{chapter.scanlator}
{chapter.scanlator && ' '}
{dateStr}
2021-05-30 04:01:49 +04:30
{downloadingString}
</Typography>
</div>
</div>
2021-03-23 03:50:55 +04:30
</Link>
<IconButton aria-label="more" onClick={handleClick}>
<MoreVertIcon />
</IconButton>
<Menu
anchorEl={anchorEl}
keepMounted
open={Boolean(anchorEl)}
onClose={handleClose}
>
2021-05-30 04:01:49 +04:30
{downloadingString.length === 0
&& <MenuItem onClick={downloadChapter}>Download</MenuItem> }
2021-05-14 17:31:07 +04:30
<MenuItem onClick={() => sendChange('bookmarked', !chapter.bookmarked)}>
{chapter.bookmarked && 'Remove bookmark'}
{!chapter.bookmarked && 'Bookmark'}
</MenuItem>
<MenuItem onClick={() => sendChange('read', !chapter.read)}>
Mark as
{' '}
{chapter.read && 'unread'}
{!chapter.read && 'read'}
</MenuItem>
<MenuItem onClick={() => sendChange('markPrevRead', true)}>
Mark previous as Read
</MenuItem>
</Menu>
2021-01-19 20:20:28 +03:30
</CardContent>
</Card>
</li>
</>
);
}