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 FilterList from '@mui/icons-material/FilterList';
|
2024-04-14 15:50:12 +02:00
|
|
|
import IconButton from '@mui/material/IconButton';
|
2022-11-09 18:09:15 +01:00
|
|
|
import * as React from 'react';
|
2023-11-05 17:22:29 +01:00
|
|
|
import { useTranslation } from 'react-i18next';
|
2025-05-20 23:30:19 +02:00
|
|
|
import PopupState, { bindMenu, bindTrigger } from 'material-ui-popup-state';
|
|
|
|
|
import Menu from '@mui/material/Menu';
|
|
|
|
|
import DownloadIcon from '@mui/icons-material/Download';
|
|
|
|
|
import DoneAllIcon from '@mui/icons-material/DoneAll';
|
2025-07-05 17:03:17 +02:00
|
|
|
import { useMemo } from 'react';
|
2025-08-16 02:48:46 +02:00
|
|
|
import { CustomTooltip } from '@/base/components/CustomTooltip.tsx';
|
2025-08-15 22:02:58 +02:00
|
|
|
import { ChapterOptions } from '@/features/chapter/components/ChapterOptions.tsx';
|
|
|
|
|
import { isFilterActive, updateChapterListOptions } from '@/features/chapter/utils/ChapterList.util.tsx';
|
2025-05-20 23:30:19 +02:00
|
|
|
import {
|
|
|
|
|
ChapterBookmarkInfo,
|
|
|
|
|
ChapterDownloadInfo,
|
|
|
|
|
ChapterIdInfo,
|
|
|
|
|
ChapterListOptions,
|
2025-07-05 17:03:17 +02:00
|
|
|
ChapterReadInfo,
|
2025-08-15 22:02:58 +02:00
|
|
|
} from '@/features/chapter/Chapter.types.ts';
|
|
|
|
|
import { ChaptersDownloadActionMenuItems } from '@/features/chapter/components/actions/ChaptersDownloadActionMenuItems.tsx';
|
|
|
|
|
import { Chapters } from '@/features/chapter/services/Chapters.ts';
|
2022-11-09 18:09:15 +01:00
|
|
|
|
|
|
|
|
interface IProps {
|
2025-05-20 23:30:19 +02:00
|
|
|
mangaId: number;
|
2023-02-06 10:06:33 +01:00
|
|
|
options: ChapterListOptions;
|
2025-04-20 21:40:28 +02:00
|
|
|
updateOption: ReturnType<typeof updateChapterListOptions>;
|
2025-07-05 17:03:17 +02:00
|
|
|
chapters: (ChapterIdInfo & ChapterReadInfo & ChapterDownloadInfo & ChapterBookmarkInfo)[];
|
2025-06-09 15:32:04 +02:00
|
|
|
scanlators: string[];
|
|
|
|
|
excludeScanlators: string[];
|
2022-11-09 18:09:15 +01:00
|
|
|
}
|
|
|
|
|
|
2025-05-20 23:30:19 +02:00
|
|
|
export const ChaptersToolbarMenu = ({
|
|
|
|
|
mangaId,
|
|
|
|
|
options,
|
|
|
|
|
updateOption,
|
2025-07-05 17:03:17 +02:00
|
|
|
chapters,
|
2025-06-09 15:32:04 +02:00
|
|
|
scanlators,
|
|
|
|
|
excludeScanlators,
|
2025-05-20 23:30:19 +02:00
|
|
|
}: IProps) => {
|
2023-11-05 17:22:29 +01:00
|
|
|
const { t } = useTranslation();
|
|
|
|
|
|
2022-11-09 18:09:15 +01:00
|
|
|
const [open, setOpen] = React.useState(false);
|
|
|
|
|
const isFiltered = isFilterActive(options);
|
|
|
|
|
|
2025-07-05 17:03:17 +02:00
|
|
|
const areAllChaptersRead = useMemo(() => chapters.every(Chapters.isRead), [chapters]);
|
|
|
|
|
const areAllChaptersDownloaded = useMemo(() => chapters.every(Chapters.isDownloaded), [chapters]);
|
|
|
|
|
|
2022-11-09 18:09:15 +01:00
|
|
|
return (
|
|
|
|
|
<>
|
2025-05-20 23:30:19 +02:00
|
|
|
<CustomTooltip
|
|
|
|
|
title={t('chapter.action.mark_as_read.add.label.action.current')}
|
|
|
|
|
disabled={areAllChaptersRead}
|
|
|
|
|
>
|
|
|
|
|
<IconButton
|
|
|
|
|
disabled={areAllChaptersRead}
|
2025-07-05 17:03:17 +02:00
|
|
|
onClick={() => Chapters.markAsRead(Chapters.getNonRead(chapters), true, mangaId)}
|
2025-05-20 23:30:19 +02:00
|
|
|
color="inherit"
|
|
|
|
|
>
|
|
|
|
|
<DoneAllIcon />
|
|
|
|
|
</IconButton>
|
|
|
|
|
</CustomTooltip>
|
|
|
|
|
<PopupState variant="popover" popupId="chapterlist-download-button">
|
|
|
|
|
{(popupState) => (
|
|
|
|
|
<>
|
|
|
|
|
<CustomTooltip
|
|
|
|
|
title={t('chapter.action.download.add.label.action')}
|
|
|
|
|
disabled={areAllChaptersRead}
|
|
|
|
|
>
|
|
|
|
|
<IconButton
|
|
|
|
|
disabled={areAllChaptersDownloaded}
|
|
|
|
|
{...bindTrigger(popupState)}
|
|
|
|
|
color="inherit"
|
|
|
|
|
>
|
|
|
|
|
<DownloadIcon />
|
|
|
|
|
</IconButton>
|
|
|
|
|
</CustomTooltip>
|
|
|
|
|
{popupState.isOpen && (
|
|
|
|
|
<Menu {...bindMenu(popupState)}>
|
|
|
|
|
<ChaptersDownloadActionMenuItems mangaIds={[mangaId]} closeMenu={popupState.close} />
|
|
|
|
|
</Menu>
|
|
|
|
|
)}
|
|
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
</PopupState>
|
2025-02-01 14:24:38 +01:00
|
|
|
<CustomTooltip title={t('settings.title')}>
|
2025-01-26 03:26:24 +01:00
|
|
|
<IconButton onClick={() => setOpen(true)} color="inherit">
|
2023-11-05 17:22:29 +01:00
|
|
|
<FilterList color={isFiltered ? 'warning' : undefined} />
|
|
|
|
|
</IconButton>
|
2025-02-01 14:24:38 +01:00
|
|
|
</CustomTooltip>
|
2025-06-09 15:32:04 +02:00
|
|
|
<ChapterOptions
|
|
|
|
|
open={open}
|
|
|
|
|
onClose={() => setOpen(false)}
|
|
|
|
|
options={options}
|
|
|
|
|
updateOption={updateOption}
|
|
|
|
|
scanlators={scanlators}
|
|
|
|
|
excludedScanlators={excludeScanlators}
|
|
|
|
|
/>
|
2022-11-09 18:09:15 +01:00
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
};
|