/* * Copyright (C) Contributors to the Suwayomi project * * 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/. */ import BookmarkIcon from '@mui/icons-material/Bookmark'; import BookmarkAdd from '@mui/icons-material/BookmarkAdd'; import BookmarkRemove from '@mui/icons-material/BookmarkRemove'; import CheckBoxOutlineBlank from '@mui/icons-material/CheckBoxOutlineBlank'; import Delete from '@mui/icons-material/Delete'; import Done from '@mui/icons-material/Done'; import DoneAll from '@mui/icons-material/DoneAll'; import Download from '@mui/icons-material/Download'; import MoreVertIcon from '@mui/icons-material/MoreVert'; import RemoveDone from '@mui/icons-material/RemoveDone'; import { LinearProgress, Checkbox, ListItemIcon, ListItemText, Stack, } from '@mui/material'; import Card from '@mui/material/Card'; import CardContent from '@mui/material/CardContent'; import IconButton from '@mui/material/IconButton'; import Menu from '@mui/material/Menu'; import MenuItem from '@mui/material/MenuItem'; import { useTheme } from '@mui/material/styles'; import Typography from '@mui/material/Typography'; import React from 'react'; import { Link } from 'react-router-dom'; import client from 'util/client'; interface IProps{ chapter: IChapter triggerChaptersUpdate: () => void downloadChapter: IDownloadChapter | undefined showChapterNumber: boolean onSelect: (selected: boolean) => void selected: boolean | null } const ChapterCard: React.FC = (props: IProps) => { const theme = useTheme(); const { chapter, triggerChaptersUpdate, downloadChapter: dc, showChapterNumber, onSelect, selected, } = props; const isSelecting = selected !== null; const dateStr = chapter.uploadDate && new Date(chapter.uploadDate).toLocaleDateString(); const [anchorEl, setAnchorEl] = React.useState(null); const handleMenuClick = (event: React.MouseEvent) => { // prevent parent tags from getting the event event.stopPropagation(); event.preventDefault(); setAnchorEl(event.currentTarget); }; const handleClose = () => { setAnchorEl(null); }; const sendChange = (key: string, value: any) => { handleClose(); const formData = new FormData(); formData.append(key, value); if (key === 'read') { formData.append('lastPageRead', '1'); } client.patch(`/api/v1/manga/${chapter.mangaId}/chapter/${chapter.index}`, formData) .then(() => triggerChaptersUpdate()); }; const downloadChapter = () => { client.get(`/api/v1/download/${chapter.mangaId}/chapter/${chapter.index}`); handleClose(); }; const deleteChapter = () => { client.delete(`/api/v1/manga/${chapter.mangaId}/chapter/${chapter.index}`) .then(() => triggerChaptersUpdate()); handleClose(); }; const handleSelect = () => { onSelect(true); handleClose(); }; const handleClick = (event: React.MouseEvent) => { if (isSelecting) { event.preventDefault(); event.stopPropagation(); onSelect(!selected); } }; const isDownloaded = chapter.downloaded; const canBeDownloaded = !chapter.downloaded && dc === undefined; return (
  • {chapter.bookmarked && ( )} { showChapterNumber ? `Chapter ${chapter.chapterNumber}` : chapter.name} {chapter.scanlator} {dateStr} {isDownloaded && ' • Downloaded'} {dc && ` • Downloading (${(dc.progress * 100).toFixed(2)}%)`} {selected === null ? ( ) : ( )} {dc != null && ( )} Select {isDownloaded && ( Delete )} {canBeDownloaded && ( Download ) } sendChange('bookmarked', !chapter.bookmarked)}> {chapter.bookmarked && } {!chapter.bookmarked && } {chapter.bookmarked && 'Remove bookmark'} {!chapter.bookmarked && 'Add bookmark'} sendChange('read', !chapter.read)}> {chapter.read && } {!chapter.read && } {chapter.read && 'Mark as unread'} {!chapter.read && 'Mark as read'} sendChange('markPrevRead', true)}> Mark previous as Read
  • ); }; export default ChapterCard;