Add manga to default categories when adding to library
This commit is contained in:
@@ -167,6 +167,10 @@ function getValueOrUnknown(val?: string | null) {
|
|||||||
|
|
||||||
const MangaDetails: React.FC<IProps> = ({ manga }) => {
|
const MangaDetails: React.FC<IProps> = ({ manga }) => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
const { data: categoriesData, loading: areCategoriesLoading } = requestManager.useGetCategories();
|
||||||
|
const categories = categoriesData?.categories.nodes ?? [];
|
||||||
|
const defaultCategoryIds = categories.filter((category) => category.default).map((category) => category.id);
|
||||||
|
const [updateMangaCategories] = requestManager.useUpdateMangaCategories();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!manga.source) {
|
if (!manga.source) {
|
||||||
@@ -175,11 +179,24 @@ const MangaDetails: React.FC<IProps> = ({ manga }) => {
|
|||||||
}, [manga.source]);
|
}, [manga.source]);
|
||||||
|
|
||||||
const addToLibrary = () => {
|
const addToLibrary = () => {
|
||||||
requestManager.updateManga(manga.id, { inLibrary: true });
|
Promise.all([
|
||||||
|
requestManager.updateManga(manga.id, { inLibrary: true }).response,
|
||||||
|
updateMangaCategories({
|
||||||
|
variables: { input: { id: manga.id, patch: { addToCategories: defaultCategoryIds } } },
|
||||||
|
}),
|
||||||
|
])
|
||||||
|
.then(() => makeToast(t('library.info.label.added_to_library'), 'success'))
|
||||||
|
.catch(() => {
|
||||||
|
makeToast(t('library.error.label.add_to_library'), 'error');
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const removeFromLibrary = () => {
|
const removeFromLibrary = () => {
|
||||||
requestManager.updateManga(manga.id, { inLibrary: false });
|
Promise.all([requestManager.updateManga(manga.id, { inLibrary: false }).response])
|
||||||
|
.then(() => makeToast(t('library.info.label.removed_from_library'), 'success'))
|
||||||
|
.catch(() => {
|
||||||
|
makeToast(t('library.error.label.remove_from_library'), 'error');
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -208,6 +225,7 @@ const MangaDetails: React.FC<IProps> = ({ manga }) => {
|
|||||||
<MangaButtonsContainer inLibrary={manga.inLibrary}>
|
<MangaButtonsContainer inLibrary={manga.inLibrary}>
|
||||||
<div>
|
<div>
|
||||||
<Button
|
<Button
|
||||||
|
disabled={areCategoriesLoading}
|
||||||
startIcon={manga.inLibrary ? <FavoriteIcon /> : <FavoriteBorderIcon />}
|
startIcon={manga.inLibrary ? <FavoriteIcon /> : <FavoriteBorderIcon />}
|
||||||
onClick={manga.inLibrary ? removeFromLibrary : addToLibrary}
|
onClick={manga.inLibrary ? removeFromLibrary : addToLibrary}
|
||||||
size="large"
|
size="large"
|
||||||
|
|||||||
@@ -268,7 +268,15 @@
|
|||||||
"error": {
|
"error": {
|
||||||
"label": {
|
"label": {
|
||||||
"empty": "Your library is empty",
|
"empty": "Your library is empty",
|
||||||
"no_matches": "No manga matches this filter"
|
"no_matches": "No manga matches this filter",
|
||||||
|
"add_to_library": "Added manga to library!",
|
||||||
|
"remove_from_library": "Could not add manga to library!"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"info": {
|
||||||
|
"label": {
|
||||||
|
"added_to_library": "Added manga to library!",
|
||||||
|
"removed_from_library": "Removed manga from library!"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"option": {
|
"option": {
|
||||||
|
|||||||
Reference in New Issue
Block a user