Require manga library removal confirmation only in source browse

This commit is contained in:
schroda
2024-04-21 03:50:41 +02:00
parent c877ea23d3
commit 6f90eea762
2 changed files with 19 additions and 10 deletions

View File

@@ -46,7 +46,10 @@ export const MangaCard = (props: MangaCardProps) => {
options: { showContinueReadingButton }, options: { showContinueReadingButton },
} = useLibraryOptionsContext(); } = useLibraryOptionsContext();
const { CategorySelectComponent, updateLibraryState, isInLibrary } = useManageMangaLibraryState(manga); const { CategorySelectComponent, updateLibraryState, isInLibrary } = useManageMangaLibraryState(
manga,
mode === 'source',
);
const mangaLinkTo = getMangaLinkTo(mode, manga.id, manga.source?.id, manga.title); const mangaLinkTo = getMangaLinkTo(mode, manga.id, manga.source?.id, manga.title);

View File

@@ -18,7 +18,10 @@ import { Mangas } from '@/lib/data/Mangas.ts';
import { TManga } from '@/typings.ts'; import { TManga } from '@/typings.ts';
import { awaitConfirmation } from '@/lib/ui/AwaitableDialog.tsx'; import { awaitConfirmation } from '@/lib/ui/AwaitableDialog.tsx';
export const useManageMangaLibraryState = (manga: Pick<TManga, 'id' | 'title' | 'inLibrary'>) => { export const useManageMangaLibraryState = (
manga: Pick<TManga, 'id' | 'title' | 'inLibrary'>,
confirmRemoval: boolean = false,
) => {
const { t } = useTranslation(); const { t } = useTranslation();
const [isInLibrary, setIsInLibrary] = useState(manga.inLibrary); const [isInLibrary, setIsInLibrary] = useState(manga.inLibrary);
@@ -55,16 +58,19 @@ export const useManageMangaLibraryState = (manga: Pick<TManga, 'id' | 'title' |
); );
const removeFromLibrary = useCallback(async () => { const removeFromLibrary = useCallback(async () => {
await awaitConfirmation({ if (confirmRemoval) {
title: t('global.label.are_you_sure'), await awaitConfirmation({
message: t('manga.action.library.remove.dialog.label.message', { title: manga.title }), title: t('global.label.are_you_sure'),
actions: { message: t('manga.action.library.remove.dialog.label.message', { title: manga.title }),
confirm: { title: t('global.button.remove') }, actions: {
}, confirm: { title: t('global.button.remove') },
}); },
});
}
await Mangas.removeFromLibrary([manga.id]); await Mangas.removeFromLibrary([manga.id]);
setIsInLibrary(false); setIsInLibrary(false);
}, [manga.id]); }, [manga.id, confirmRemoval]);
const { openCategorySelect, CategorySelectComponent } = useCategorySelect({ const { openCategorySelect, CategorySelectComponent } = useCategorySelect({
mangaId: manga.id, mangaId: manga.id,