diff --git a/src/features/category/components/CategorySelect.tsx b/src/features/category/components/CategorySelect.tsx
index 0e113798..a9da321a 100644
--- a/src/features/category/components/CategorySelect.tsx
+++ b/src/features/category/components/CategorySelect.tsx
@@ -37,8 +37,8 @@ import { AppRoutes } from '@/base/AppRoute.constants.ts';
import { getErrorMessage } from '@/lib/HelperFunctions.ts';
type BaseProps = {
- open: boolean;
- onClose: (didUpdateCategories: boolean, addToCategories?: number[], removeFromCategories?: number[]) => void;
+ onCancel: () => void;
+ onConfirm: (selectedCategories: { addToCategories?: number[]; removeFromCategories?: number[] }) => void;
};
type SingleMangaModeProps = {
@@ -94,7 +94,7 @@ const getCategoryCheckedState = (
export function CategorySelect(props: CategorySelectProps) {
const { t } = useTranslation();
- const { open, onClose, mangaId, mangaIds: passedMangaIds, addToLibrary = false } = props;
+ const { onCancel, onConfirm, mangaId, mangaIds: passedMangaIds, addToLibrary = false } = props;
const isSingleSelectionMode = mangaId !== undefined;
const mangaIds = passedMangaIds ?? [mangaId];
@@ -137,7 +137,7 @@ export function CategorySelect(props: CategorySelectProps) {
const handleCancel = () => {
setSelectionForKey('categoriesToAdd', mangaCategoryIds);
setSelectionForKey('categoriesToRemove', []);
- onClose(false);
+ onCancel();
};
const handleOk = () => {
@@ -148,7 +148,10 @@ export function CategorySelect(props: CategorySelectProps) {
? mangaCategoryIds.filter((categoryId) => !categoriesToAdd.includes(categoryId))
: categoriesToRemove;
- onClose(true, addToCategories, removeFromCategories);
+ onConfirm({
+ addToCategories,
+ removeFromCategories,
+ });
if (doNotShowAddToLibraryDialogAgain) {
updateMetadataServerSettings('showAddToLibraryCategorySelectDialog', false).catch((e) =>
@@ -183,7 +186,7 @@ export function CategorySelect(props: CategorySelectProps) {
},
}}
maxWidth="xs"
- open={open}
+ open
onClose={handleCancel}
>
{t('category.title.set_categories')}
diff --git a/src/features/category/hooks/useCategorySelect.tsx b/src/features/category/hooks/useCategorySelect.tsx
deleted file mode 100644
index f602786b..00000000
--- a/src/features/category/hooks/useCategorySelect.tsx
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * 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 { useMemo, useState } from 'react';
-import { CategorySelect, CategorySelectProps } from '@/features/category/components/CategorySelect.tsx';
-
-export const useCategorySelect = ({
- mangaId,
- mangaIds,
- onClose,
- addToLibrary,
-}: Omit & Pick, 'onClose'>) => {
- const [isCategorySelectOpen, setIsCategorySelectOpen] = useState(false);
-
- const CategorySelectComponent = useMemo(() => {
- if (!isCategorySelectOpen) {
- return null;
- }
-
- return (
- {
- setIsCategorySelectOpen(false);
- onClose?.(...args);
- }}
- mangaId={mangaId!} // either mangaId or mangaIds is undefined, however, ts is not able to infer it correctly and raises an error
- mangaIds={mangaIds as undefined}
- addToLibrary={addToLibrary}
- />
- );
- }, [mangaId, mangaIds, addToLibrary, onClose, isCategorySelectOpen]);
-
- return {
- openCategorySelect: setIsCategorySelectOpen,
- CategorySelectComponent,
- };
-};
diff --git a/src/features/manga/components/MangaActionMenuItems.tsx b/src/features/manga/components/MangaActionMenuItems.tsx
index b5776d9f..f3aa2a5b 100644
--- a/src/features/manga/components/MangaActionMenuItems.tsx
+++ b/src/features/manga/components/MangaActionMenuItems.tsx
@@ -29,17 +29,16 @@ import {
} from '@/base/components/menu/Menu.utils.ts';
import { defaultPromiseErrorHandler } from '@/lib/DefaultPromiseErrorHandler.ts';
import { TrackManga } from '@/features/tracker/components/TrackManga.tsx';
-import { useCategorySelect } from '@/features/category/hooks/useCategorySelect.tsx';
import { ChaptersDownloadActionMenuItems } from '@/features/chapter/components/actions/ChaptersDownloadActionMenuItems.tsx';
import { NestedMenuItem } from '@/base/components/menu/NestedMenuItem.tsx';
import { MangaChapterStatFieldsFragment, MangaType } from '@/lib/graphql/generated/graphql.ts';
import { MangaAction, MangaDownloadInfo, MangaIdInfo, MangaUnreadInfo } from '@/features/manga/Manga.types.ts';
import { MANGA_ACTION_TO_TRANSLATION } from '@/features/manga/Manga.constants.ts';
import { AppRoutes } from '@/base/AppRoute.constants.ts';
+import { GlobalDialogManager } from '@/base/global-dialog/GlobalDialogManager.tsx';
+import { CategorySelect } from '@/features/category/components/CategorySelect.tsx';
-const ACTION_DISABLES_SELECTION_MODE: MangaAction[] = ['remove_from_library'] as const;
-
-type BaseProps = { onClose: (selectionModeState: boolean) => void; setHideMenu: (hide: boolean) => void };
+type BaseProps = { onClose: () => void; setHideMenu: (hide: boolean) => void };
export type SingleModeProps = {
manga: Pick & MangaDownloadInfo & MangaUnreadInfo;
@@ -77,16 +76,9 @@ export const MangaActionMenuItems = ({
const hasUnreadChapters = !!manga?.unreadCount;
const hasReadChapters = !!manga && manga.unreadCount !== manga.chapters.totalCount;
- const { openCategorySelect, CategorySelectComponent } = useCategorySelect({
- mangaId: manga?.id,
- mangaIds: passedSelectedMangas ? Mangas.getIds(selectedMangas) : undefined,
- onClose: () => onClose(true),
- addToLibrary: false,
- });
-
const handleSelect = () => {
handleSelection?.(manga.id, true);
- onClose(true);
+ onClose();
};
const performAction = (action: MangaAction, mangas: MangaIdInfo[]) => {
@@ -94,7 +86,7 @@ export const MangaActionMenuItems = ({
wasManuallyMarkedAsRead: true,
}).catch(defaultPromiseErrorHandler(`MangaActionMenuItems:performAction(${action})`));
- onClose(!ACTION_DISABLES_SELECTION_MODE.includes(action));
+ onClose();
};
const { downloadableMangas, downloadedMangas, unreadMangas, readMangas } = useMemo(
@@ -127,7 +119,7 @@ export const MangaActionMenuItems = ({
>
onClose(true)}
+ closeMenu={onClose}
/>
)}
@@ -176,8 +168,13 @@ export const MangaActionMenuItems = ({
)}