2022-11-09 18:09:15 +01:00
|
|
|
/*
|
|
|
|
|
* 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
|
2023-05-18 13:17:41 +02:00
|
|
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
|
|
|
*/
|
2022-11-09 18:09:15 +01:00
|
|
|
|
|
|
|
|
import BookmarkIcon from '@mui/icons-material/Bookmark';
|
|
|
|
|
import MoreVertIcon from '@mui/icons-material/MoreVert';
|
2023-12-30 04:04:59 +01:00
|
|
|
import { CardActionArea, Checkbox, Stack, Tooltip } from '@mui/material';
|
2022-11-09 18:09:15 +01:00
|
|
|
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';
|
2024-04-05 02:03:00 +02:00
|
|
|
import React, { MouseEvent, TouchEvent } from 'react';
|
2022-11-09 18:09:15 +01:00
|
|
|
import { Link } from 'react-router-dom';
|
2023-03-23 13:59:32 +01:00
|
|
|
import { useTranslation } from 'react-i18next';
|
2023-12-30 04:04:59 +01:00
|
|
|
import PopupState, { bindMenu, bindTrigger } from 'material-ui-popup-state';
|
2024-04-05 02:03:00 +02:00
|
|
|
import { useLongPress } from 'use-long-press';
|
2023-12-30 14:30:04 +01:00
|
|
|
import { getUploadDateString } from '@/util/date.ts';
|
|
|
|
|
import { DownloadStateIndicator } from '@/components/molecules/DownloadStateIndicator.tsx';
|
2023-12-30 04:04:59 +01:00
|
|
|
import { DownloadType } from '@/lib/graphql/generated/graphql.ts';
|
2023-10-15 16:03:08 +02:00
|
|
|
import { TChapter } from '@/typings.ts';
|
2023-12-30 14:30:04 +01:00
|
|
|
import { ChapterActionMenuItems } from '@/components/chapter/ChapterActionMenuItems.tsx';
|
|
|
|
|
import { Menu } from '@/components/menu/Menu.tsx';
|
2022-11-09 18:09:15 +01:00
|
|
|
|
2023-01-07 16:46:07 +01:00
|
|
|
interface IProps {
|
2023-10-15 16:03:08 +02:00
|
|
|
chapter: TChapter;
|
2023-11-19 21:17:35 +01:00
|
|
|
allChapters: TChapter[];
|
2023-10-04 22:34:32 +02:00
|
|
|
downloadChapter: DownloadType | undefined;
|
2023-02-06 10:06:33 +01:00
|
|
|
showChapterNumber: boolean;
|
2024-04-05 02:03:00 +02:00
|
|
|
onSelect: (selected: boolean, isShiftKey?: boolean) => void;
|
2023-02-06 10:06:33 +01:00
|
|
|
selected: boolean | null;
|
2022-11-09 18:09:15 +01:00
|
|
|
}
|
|
|
|
|
|
2023-10-28 00:32:02 +02:00
|
|
|
export const ChapterCard: React.FC<IProps> = (props: IProps) => {
|
2023-03-23 13:59:32 +01:00
|
|
|
const { t } = useTranslation();
|
2022-11-09 18:09:15 +01:00
|
|
|
const theme = useTheme();
|
|
|
|
|
|
2023-11-19 21:17:35 +01:00
|
|
|
const { chapter, allChapters, downloadChapter: dc, showChapterNumber, onSelect, selected } = props;
|
2022-11-09 18:09:15 +01:00
|
|
|
const isSelecting = selected !== null;
|
|
|
|
|
|
2024-04-05 02:03:00 +02:00
|
|
|
const { isDownloaded } = chapter;
|
|
|
|
|
|
|
|
|
|
const handleClick = (e: MouseEvent | TouchEvent) => {
|
|
|
|
|
if (!isSelecting) return;
|
|
|
|
|
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
onSelect(!selected, e.shiftKey);
|
2022-11-09 18:09:15 +01:00
|
|
|
};
|
|
|
|
|
|
2024-04-05 02:03:00 +02:00
|
|
|
const longPressBind = useLongPress((e) => {
|
|
|
|
|
e.shiftKey = true;
|
|
|
|
|
handleClick(e);
|
|
|
|
|
});
|
2022-11-09 18:09:15 +01:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<li>
|
2023-12-30 04:04:59 +01:00
|
|
|
<PopupState variant="popover" popupId="chapter-card-action-menu">
|
|
|
|
|
{(popupState) => {
|
|
|
|
|
const bindTriggerProps = bindTrigger(popupState);
|
|
|
|
|
|
|
|
|
|
const preventDefaultAction = (e: React.BaseSyntheticEvent<unknown>) => {
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleClickOpenMenu = (e: React.BaseSyntheticEvent<unknown>) => {
|
|
|
|
|
preventDefaultAction(e);
|
|
|
|
|
bindTriggerProps.onClick(e as any);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleTouchStart = (e: React.BaseSyntheticEvent<unknown>) => {
|
|
|
|
|
preventDefaultAction(e);
|
|
|
|
|
bindTriggerProps.onTouchStart(e as TouchEvent);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<Card
|
|
|
|
|
sx={{
|
|
|
|
|
position: 'relative',
|
|
|
|
|
margin: 1,
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<CardActionArea
|
|
|
|
|
component={Link}
|
|
|
|
|
to={`/manga/${chapter.manga.id}/chapter/${chapter.sourceOrder}`}
|
|
|
|
|
style={{
|
|
|
|
|
color: theme.palette.text[chapter.isRead ? 'disabled' : 'primary'],
|
|
|
|
|
}}
|
2024-04-05 02:03:00 +02:00
|
|
|
onClick={(e) => handleClick(e)}
|
|
|
|
|
{...longPressBind()}
|
2023-12-30 04:04:59 +01:00
|
|
|
>
|
|
|
|
|
<CardContent
|
|
|
|
|
sx={{
|
|
|
|
|
display: 'flex',
|
|
|
|
|
justifyContent: 'space-between',
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
padding: 2,
|
|
|
|
|
'&:last-child': { pb: 2 },
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Stack direction="column" flex={1}>
|
|
|
|
|
<Typography variant="h5" component="h2">
|
|
|
|
|
{chapter.isBookmarked && (
|
|
|
|
|
<BookmarkIcon
|
|
|
|
|
color="primary"
|
|
|
|
|
sx={{ mr: 0.5, position: 'relative', top: '0.15em' }}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
{showChapterNumber
|
|
|
|
|
? `${t('chapter.title')} ${chapter.chapterNumber}`
|
|
|
|
|
: chapter.name}
|
|
|
|
|
</Typography>
|
|
|
|
|
<Typography variant="caption">{chapter.scanlator}</Typography>
|
|
|
|
|
<Typography variant="caption">
|
|
|
|
|
{getUploadDateString(Number(chapter.uploadDate ?? 0))}
|
|
|
|
|
{isDownloaded && ` • ${t('chapter.status.label.downloaded')}`}
|
|
|
|
|
</Typography>
|
|
|
|
|
</Stack>
|
|
|
|
|
|
|
|
|
|
{dc && <DownloadStateIndicator download={dc} />}
|
|
|
|
|
|
|
|
|
|
{selected === null ? (
|
|
|
|
|
<Tooltip title={t('global.button.options')}>
|
|
|
|
|
<IconButton
|
|
|
|
|
{...bindTriggerProps}
|
|
|
|
|
onClick={handleClickOpenMenu}
|
|
|
|
|
onTouchStart={handleTouchStart}
|
|
|
|
|
aria-label="more"
|
|
|
|
|
size="large"
|
|
|
|
|
>
|
|
|
|
|
<MoreVertIcon />
|
|
|
|
|
</IconButton>
|
|
|
|
|
</Tooltip>
|
|
|
|
|
) : (
|
|
|
|
|
<Tooltip
|
|
|
|
|
title={t(selected ? 'global.button.deselect' : 'global.button.select')}
|
|
|
|
|
>
|
|
|
|
|
<Checkbox checked={selected} />
|
|
|
|
|
</Tooltip>
|
|
|
|
|
)}
|
|
|
|
|
</CardContent>
|
|
|
|
|
</CardActionArea>
|
|
|
|
|
</Card>
|
|
|
|
|
{!isSelecting && popupState.isOpen && (
|
|
|
|
|
<Menu {...bindMenu(popupState)}>
|
|
|
|
|
{(onClose) => (
|
|
|
|
|
<ChapterActionMenuItems
|
|
|
|
|
onClose={onClose}
|
|
|
|
|
chapter={chapter}
|
|
|
|
|
allChapters={allChapters}
|
|
|
|
|
handleSelection={() => onSelect(true)}
|
|
|
|
|
canBeDownloaded={!chapter.isDownloaded && !dc}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
</Menu>
|
|
|
|
|
)}
|
|
|
|
|
</>
|
|
|
|
|
);
|
2022-11-09 18:09:15 +01:00
|
|
|
}}
|
2023-12-30 04:04:59 +01:00
|
|
|
</PopupState>
|
2022-11-09 18:09:15 +01:00
|
|
|
</li>
|
|
|
|
|
);
|
|
|
|
|
};
|