Use gql for "updating mangas"

This commit is contained in:
schroda
2023-09-01 20:33:35 +02:00
parent e1f338d013
commit c75e184c57
3 changed files with 70 additions and 40 deletions

View File

@@ -152,12 +152,16 @@ const MangaDetails: React.FC<IProps> = ({ manga }) => {
const addToLibrary = () => {
mutate(`/api/v1/manga/${manga.id}`, { ...manga, inLibrary: true }, { revalidate: false });
requestManager.addMangaToLibrary(manga.id).response.then(() => mutate(`/api/v1/manga/${manga.id}`));
requestManager
.updateManga(manga.id, { inLibrary: true })
.response.then(() => mutate(`/api/v1/manga/${manga.id}`));
};
const removeFromLibrary = () => {
mutate(`/api/v1/manga/${manga.id}`, { ...manga, inLibrary: false }, { revalidate: false });
requestManager.removeMangaFromLibrary(manga.id).response.then(() => mutate(`/api/v1/manga/${manga.id}`));
requestManager
.updateManga(manga.id, { inLibrary: false })
.response.then(() => mutate(`/api/v1/manga/${manga.id}`));
};
return (

View File

@@ -31,6 +31,7 @@ export default function CategorySelect(props: IProps) {
const { data: mangaCategoriesData, mutate } = requestManager.useGetMangaCategories(mangaId);
const { data: categoriesData } = requestManager.useGetCategories();
const [triggerMutate] = requestManager.useUpdateMangaCategories();
const allCategories = useMemo(() => {
const cats = [...(categoriesData ?? [])]; // make copy
@@ -53,10 +54,18 @@ export default function CategorySelect(props: IProps) {
const handleChange = (event: React.ChangeEvent<HTMLInputElement>, categoryId: number) => {
const { checked } = event.target as HTMLInputElement;
(checked
? requestManager.addMangaToCategory(mangaId, categoryId)
: requestManager.removeMangaFromCategory(mangaId, categoryId)
).response.then(() => mutate());
// TODO - update to only update categories when clicking OK - can now be updated in one go with graphql
triggerMutate({
variables: {
input: {
id: mangaId,
patch: {
addToCategories: checked ? [categoryId] : [],
removeFromCategories: !checked ? [categoryId] : [],
},
},
},
}).then(() => mutate());
};
return (