/* * 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 MoreVertIcon from '@mui/icons-material/MoreVert'; import { CardActionArea, Checkbox, Stack, Tooltip } from '@mui/material'; import Card from '@mui/material/Card'; import CardContent from '@mui/material/CardContent'; import IconButton from '@mui/material/IconButton'; import { useTheme } from '@mui/material/styles'; import Typography from '@mui/material/Typography'; import React, { TouchEvent } from 'react'; import { Link } from 'react-router-dom'; import { useTranslation } from 'react-i18next'; import PopupState, { bindMenu, bindTrigger } from 'material-ui-popup-state'; import { getUploadDateString } from '@/util/date.ts'; import { DownloadStateIndicator } from '@/components/molecules/DownloadStateIndicator.tsx'; import { DownloadType } from '@/lib/graphql/generated/graphql.ts'; import { TChapter } from '@/typings.ts'; import { ChapterActionMenuItems } from '@/components/chapter/ChapterActionMenuItems.tsx'; import { Menu } from '@/components/menu/Menu.tsx'; interface IProps { chapter: TChapter; allChapters: TChapter[]; downloadChapter: DownloadType | undefined; showChapterNumber: boolean; onSelect: (selected: boolean) => void; selected: boolean | null; } export const ChapterCard: React.FC = (props: IProps) => { const { t } = useTranslation(); const theme = useTheme(); const { chapter, allChapters, downloadChapter: dc, showChapterNumber, onSelect, selected } = props; const isSelecting = selected !== null; const handleClick = (event: React.MouseEvent) => { if (isSelecting) { event.preventDefault(); event.stopPropagation(); onSelect(!selected); } }; const { isDownloaded } = chapter; return (
  • {(popupState) => { const bindTriggerProps = bindTrigger(popupState); const preventDefaultAction = (e: React.BaseSyntheticEvent) => { e.stopPropagation(); e.preventDefault(); }; const handleClickOpenMenu = (e: React.BaseSyntheticEvent) => { preventDefaultAction(e); bindTriggerProps.onClick(e as any); }; const handleTouchStart = (e: React.BaseSyntheticEvent) => { preventDefaultAction(e); bindTriggerProps.onTouchStart(e as TouchEvent); }; return ( <> {chapter.isBookmarked && ( )} {showChapterNumber ? `${t('chapter.title')} ${chapter.chapterNumber}` : chapter.name} {chapter.scanlator} {getUploadDateString(Number(chapter.uploadDate ?? 0))} {isDownloaded && ` • ${t('chapter.status.label.downloaded')}`} {dc && } {selected === null ? ( ) : ( )} {!isSelecting && popupState.isOpen && ( {(onClose) => ( onSelect(true)} canBeDownloaded={!chapter.isDownloaded && !dc} /> )} )} ); }}
  • ); };