Fix/manually deleting chapter ignores bookmark (#675)

* Rename "Chapters::isAutoDeletable" to "isDeletable"

* Rename "Chapters::getAutoDeletable" to "getDeletable"

* Prevent manually deleting bookmarked chapters unless allowed
This commit is contained in:
schroda
2024-03-26 23:39:04 +01:00
committed by GitHub
parent 06b2bca340
commit 6fc70121c6
4 changed files with 36 additions and 6 deletions

View File

@@ -33,6 +33,7 @@ import { IChapterWithMeta } from '@/components/chapter/ChapterList.tsx';
import { ChaptersWithMeta } from '@/lib/data/ChaptersWithMeta.ts';
import { createGetMenuItemTitle, createIsMenuItemDisabled, createShouldShowMenuItem } from '@/components/menu/util.ts';
import { defaultPromiseErrorHandler } from '@/util/defaultPromiseErrorHandler.ts';
import { useMetadataServerSettings } from '@/lib/metadata/metadataServerSettings.ts';
type BaseProps = { onClose: () => void };
@@ -64,6 +65,10 @@ export const ChapterActionMenuItems = ({
const isSingleMode = !!chapter;
const { isDownloaded, isRead, isBookmarked } = chapter ?? {};
const {
settings: { deleteChaptersWithBookmark },
} = useMetadataServerSettings();
const getMenuItemTitle = createGetMenuItemTitle(isSingleMode, actionToTranslationKey);
const shouldShowMenuItem = createShouldShowMenuItem(isSingleMode);
const isMenuItemDisabled = createIsMenuItemDisabled(isSingleMode);
@@ -96,6 +101,19 @@ export const ChapterActionMenuItems = ({
const isMarkPrevAsRead = action === 'mark_prev_as_read';
const actualAction: ChapterAction = isMarkPrevAsRead ? 'mark_as_read' : action;
if (actualAction === 'delete' && chapter) {
const isDeletable = Chapters.isDeletable(chapter, deleteChaptersWithBookmark);
if (!isDeletable) {
onClose();
return;
}
}
if (!chaptersWithMeta.length) {
onClose();
return;
}
const getChapters = (): (ChapterDownloadInfo & ChapterBookmarkInfo & ChapterReadInfo)[] => {
// select mode
if (!chapter) {
@@ -151,7 +169,12 @@ export const ChapterActionMenuItems = ({
<MenuItem
Icon={Delete}
disabled={isMenuItemDisabled(!downloadedChapters.length)}
onClick={() => performAction('delete', downloadedChapters)}
onClick={() =>
performAction(
'delete',
ChaptersWithMeta.getDeletable(downloadedChapters, deleteChaptersWithBookmark),
)
}
title={getMenuItemTitle('delete', downloadedChapters.length)}
/>
)}