Correctly change the category of a manga from the library (#560)

For a single manga the "mangaId" should be passed while "mangaIds" is empty, however, the "mangaIds" were passed as an empty array which caused an empty array of manga ids to be passed with the mutation
This commit is contained in:
schroda
2024-01-17 13:46:05 +01:00
committed by GitHub
parent 1c2a196950
commit f8e1bfc401

View File

@@ -40,12 +40,19 @@ type Props =
| (BaseProps & SingleModeProps & PropertiesNever<SelectModeProps>)
| (BaseProps & PropertiesNever<SingleModeProps> & SelectModeProps);
export const MangaActionMenuItems = ({ manga, handleSelection, selectedMangas = [], onClose, setHideMenu }: Props) => {
export const MangaActionMenuItems = ({
manga,
handleSelection,
selectedMangas: passedSelectedMangas,
onClose,
setHideMenu,
}: Props) => {
const { t } = useTranslation();
const [isCategorySelectOpen, setIsCategorySelectOpen] = useState(false);
const isSingleMode = !!manga;
const selectedMangas = passedSelectedMangas ?? [];
const getMenuItemTitle = createGetMenuItemTitle(isSingleMode, actionToTranslationKey);
const shouldShowMenuItem = createShouldShowMenuItem(isSingleMode);
@@ -62,6 +69,7 @@ export const MangaActionMenuItems = ({ manga, handleSelection, selectedMangas =
};
const performAction = (action: MangaAction, mangas: TManga[]) => {
console.log('MangaActionMenuItem', manga);
Mangas.performAction(action, manga ? [manga.id] : Mangas.getIds(mangas), {
wasManuallyMarkedAsRead: true,
}).catch(defaultPromiseErrorHandler(`MangaActionMenuItems:performAction(${action})`));
@@ -143,7 +151,7 @@ export const MangaActionMenuItems = ({ manga, handleSelection, selectedMangas =
onClose(true);
}}
mangaId={manga?.id as undefined} // either mangaId or mangaIds is undefined, however, ts is not able to infer it correctly and raises an error
mangaIds={Mangas.getIds(selectedMangas)}
mangaIds={(passedSelectedMangas ? Mangas.getIds(selectedMangas) : undefined) as number[]}
/>
)}
</>