/* * 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 React from 'react'; import { useTheme } from '@mui/material/styles'; import { Link } from 'react-router-dom'; 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'; import client from 'util/client'; import { Box } from '@mui/system'; interface IProps{ chapter: IChapter triggerChaptersUpdate: () => void downloadStatusString: string showChapterNumber: boolean } export default function ChapterCard(props: IProps) { const theme = useTheme(); const { chapter, triggerChaptersUpdate, downloadStatusString, showChapterNumber, } = props; const dateStr = chapter.uploadDate && new Date(chapter.uploadDate).toISOString().slice(0, 10); const [anchorEl, setAnchorEl] = React.useState(null); const handleClick = (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 readChapterColor = theme.palette.mode === 'dark' ? '#acacac' : '#b0b0b0'; return ( <>
  • {chapter.bookmarked && } { showChapterNumber ? `Chapter ${chapter.chapterNumber}` : chapter.name} {chapter.scanlator} {chapter.scanlator && ' '} {dateStr} {downloadStatusString}
    {downloadStatusString.endsWith('Downloaded') && Delete} {downloadStatusString.length === 0 && Download } sendChange('bookmarked', !chapter.bookmarked)}> {chapter.bookmarked && 'Remove bookmark'} {!chapter.bookmarked && 'Bookmark'} sendChange('read', !chapter.read)}> {`Mark as ${chapter.read ? 'unread' : 'read'}`} sendChange('markPrevRead', true)}> Mark previous as Read
  • ); }