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/. */
|
|
|
|
|
|
2021-01-19 20:20:28 +03:30
|
|
|
import React from 'react';
|
2021-09-09 17:51:22 +04:30
|
|
|
import { useTheme } from '@mui/material/styles';
|
2021-11-14 00:07:43 +03:30
|
|
|
import { Link } from 'react-router-dom';
|
2021-09-09 17:51:22 +04:30
|
|
|
import Card from '@mui/material/Card';
|
|
|
|
|
import CardContent from '@mui/material/CardContent';
|
|
|
|
|
import IconButton from '@mui/material/IconButton';
|
|
|
|
|
import MoreVertIcon from '@mui/icons-material/MoreVert';
|
|
|
|
|
import Typography from '@mui/material/Typography';
|
|
|
|
|
import Menu from '@mui/material/Menu';
|
|
|
|
|
import MenuItem from '@mui/material/MenuItem';
|
|
|
|
|
import BookmarkIcon from '@mui/icons-material/Bookmark';
|
2021-11-14 00:07:43 +03:30
|
|
|
|
2021-05-27 05:13:01 +04:30
|
|
|
import client from 'util/client';
|
2021-11-15 19:33:35 +03:30
|
|
|
import { Box } from '@mui/system';
|
2021-01-19 20:20:28 +03:30
|
|
|
|
2021-01-19 21:02:57 +03:30
|
|
|
interface IProps{
|
|
|
|
|
chapter: IChapter
|
2021-05-15 13:43:26 +04:30
|
|
|
triggerChaptersUpdate: () => void
|
2021-09-17 01:26:26 +04:30
|
|
|
downloadStatusString: string
|
2021-12-13 19:52:56 +05:30
|
|
|
showChapterNumber: boolean
|
2021-01-19 21:02:57 +03:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default function ChapterCard(props: IProps) {
|
2021-05-13 17:46:40 +04:30
|
|
|
const theme = useTheme();
|
2021-11-14 00:07:43 +03:30
|
|
|
|
2021-12-13 19:52:56 +05:30
|
|
|
const {
|
|
|
|
|
chapter, triggerChaptersUpdate, downloadStatusString, showChapterNumber,
|
|
|
|
|
} = 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
|
|
|
|
2021-05-13 17:46:40 +04:30
|
|
|
const [anchorEl, setAnchorEl] = React.useState<null | HTMLElement>(null);
|
|
|
|
|
|
|
|
|
|
const handleClick = (event: React.MouseEvent<HTMLButtonElement>) => {
|
2021-11-14 00:07:43 +03:30
|
|
|
// prevent parent tags from getting the event
|
|
|
|
|
event.stopPropagation();
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
2021-05-13 17:46:40 +04:30
|
|
|
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);
|
2021-11-02 23:28:08 +05:30
|
|
|
if (key === 'read') { formData.append('lastPageRead', '1'); }
|
2021-05-15 13:43:26 +04:30
|
|
|
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-09-17 01:26:26 +04:30
|
|
|
const deleteChapter = () => {
|
|
|
|
|
client.delete(`/api/v1/manga/${chapter.mangaId}/chapter/${chapter.index}`)
|
|
|
|
|
.then(() => triggerChaptersUpdate());
|
|
|
|
|
|
|
|
|
|
handleClose();
|
|
|
|
|
};
|
|
|
|
|
|
2021-09-09 17:51:22 +04:30
|
|
|
const readChapterColor = theme.palette.mode === 'dark' ? '#acacac' : '#b0b0b0';
|
2021-11-14 00:07:43 +03:30
|
|
|
|
2021-01-19 20:20:28 +03:30
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<li>
|
2021-11-14 00:07:43 +03:30
|
|
|
<Card
|
|
|
|
|
sx={{
|
|
|
|
|
margin: '10px',
|
|
|
|
|
':hover': {
|
|
|
|
|
backgroundColor: 'action.hover',
|
|
|
|
|
transition: 'background-color 100ms cubic-bezier(0.4, 0, 0.2, 1) 0ms',
|
|
|
|
|
cursor: 'pointer',
|
|
|
|
|
},
|
|
|
|
|
':active': {
|
|
|
|
|
backgroundColor: 'action.selected',
|
|
|
|
|
transition: 'background-color 100ms cubic-bezier(0.4, 0, 0.2, 1) 0ms',
|
|
|
|
|
},
|
2021-11-02 23:28:08 +05:30
|
|
|
}}
|
2021-11-14 00:07:43 +03:30
|
|
|
>
|
|
|
|
|
<Link
|
|
|
|
|
to={`/manga/${chapter.mangaId}/chapter/${chapter.index}`}
|
|
|
|
|
style={{
|
|
|
|
|
textDecoration: 'none',
|
|
|
|
|
color: chapter.read ? readChapterColor : theme.palette.text.primary,
|
|
|
|
|
}}
|
2021-11-02 23:28:08 +05:30
|
|
|
>
|
2021-11-14 00:07:43 +03:30
|
|
|
<CardContent
|
|
|
|
|
sx={{
|
|
|
|
|
display: 'flex',
|
|
|
|
|
justifyContent: 'space-between',
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
padding: 2,
|
2021-05-13 17:46:40 +04:30
|
|
|
}}
|
2021-03-23 03:50:55 +04:30
|
|
|
>
|
2021-11-15 19:33:35 +03:30
|
|
|
<Box sx={{ display: 'flex' }}>
|
2021-05-13 17:46:40 +04:30
|
|
|
<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>
|
2021-12-13 19:52:56 +05:30
|
|
|
{ showChapterNumber ? `Chapter ${chapter.chapterNumber}` : chapter.name}
|
2021-05-13 17:46:40 +04:30
|
|
|
</Typography>
|
|
|
|
|
<Typography variant="caption" display="block" gutterBottom>
|
|
|
|
|
{chapter.scanlator}
|
|
|
|
|
{chapter.scanlator && ' '}
|
|
|
|
|
{dateStr}
|
2021-09-17 01:26:26 +04:30
|
|
|
{downloadStatusString}
|
2021-05-13 17:46:40 +04:30
|
|
|
</Typography>
|
|
|
|
|
</div>
|
2021-11-15 19:33:35 +03:30
|
|
|
</Box>
|
2021-11-14 00:07:43 +03:30
|
|
|
|
|
|
|
|
<IconButton aria-label="more" onClick={handleClick} size="large">
|
|
|
|
|
<MoreVertIcon />
|
|
|
|
|
</IconButton>
|
|
|
|
|
</CardContent>
|
|
|
|
|
</Link>
|
|
|
|
|
<Menu
|
|
|
|
|
anchorEl={anchorEl}
|
|
|
|
|
keepMounted
|
|
|
|
|
open={Boolean(anchorEl)}
|
|
|
|
|
onClose={handleClose}
|
|
|
|
|
>
|
|
|
|
|
{downloadStatusString.endsWith('Downloaded')
|
2021-11-15 19:33:35 +03:30
|
|
|
&& <MenuItem onClick={deleteChapter}>Delete</MenuItem>}
|
2021-11-14 00:07:43 +03:30
|
|
|
{downloadStatusString.length === 0
|
2021-11-15 19:33:35 +03:30
|
|
|
&& <MenuItem onClick={downloadChapter}>Download</MenuItem> }
|
2021-11-14 00:07:43 +03: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' : 'read'}`}
|
|
|
|
|
</MenuItem>
|
|
|
|
|
<MenuItem onClick={() => sendChange('markPrevRead', true)}>
|
|
|
|
|
Mark previous as Read
|
|
|
|
|
</MenuItem>
|
|
|
|
|
</Menu>
|
2021-01-19 20:20:28 +03:30
|
|
|
</Card>
|
|
|
|
|
</li>
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
}
|