refactor: Add fetchAllContentImages function and update Manga component to utilize it

This commit is contained in:
Rodrigo Verdiani 2026-03-31 10:25:39 -03:00
parent b7364bd054
commit 06c8530dfa
4 changed files with 89 additions and 117 deletions

View File

@ -192,17 +192,17 @@ export interface PageMangaImportJobDTO {
number?: number;
pageable?: PageableObject;
numberOfElements?: number;
sort?: SortObject;
first?: boolean;
last?: boolean;
sort?: SortObject;
empty?: boolean;
}
export interface PageableObject {
offset?: number;
paged?: boolean;
pageNumber?: number;
pageSize?: number;
paged?: boolean;
unpaged?: boolean;
sort?: SortObject;
}
@ -254,9 +254,9 @@ export interface PageMangaListDTO {
number?: number;
pageable?: PageableObject;
numberOfElements?: number;
sort?: SortObject;
first?: boolean;
last?: boolean;
sort?: SortObject;
empty?: boolean;
}

View File

@ -289,6 +289,69 @@ export const useFetchContentProviderContentList = <TError = unknown,
return useMutation(mutationOptions, queryClient);
}
/**
* Fetch all not yet downloaded content's images from the provider
* @summary Fetch all content's images
*/
export const fetchAllContentImages = (
mangaContentProviderId: number,
options?: SecondParameter<typeof customInstance>,signal?: AbortSignal
) => {
return customInstance<DefaultResponseDTOVoid>(
{url: `/ingestion/manga-content-providers/${encodeURIComponent(String(mangaContentProviderId))}/fetch-all-chapters`, method: 'POST', signal
},
options);
}
export const getFetchAllContentImagesMutationOptions = <TError = unknown,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof fetchAllContentImages>>, TError,{mangaContentProviderId: number}, TContext>, request?: SecondParameter<typeof customInstance>}
): UseMutationOptions<Awaited<ReturnType<typeof fetchAllContentImages>>, TError,{mangaContentProviderId: number}, TContext> => {
const mutationKey = ['fetchAllContentImages'];
const {mutation: mutationOptions, request: requestOptions} = options ?
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
options
: {...options, mutation: {...options.mutation, mutationKey}}
: {mutation: { mutationKey, }, request: undefined};
const mutationFn: MutationFunction<Awaited<ReturnType<typeof fetchAllContentImages>>, {mangaContentProviderId: number}> = (props) => {
const {mangaContentProviderId} = props ?? {};
return fetchAllContentImages(mangaContentProviderId,requestOptions)
}
return { mutationFn, ...mutationOptions }}
export type FetchAllContentImagesMutationResult = NonNullable<Awaited<ReturnType<typeof fetchAllContentImages>>>
export type FetchAllContentImagesMutationError = unknown
/**
* @summary Fetch all content's images
*/
export const useFetchAllContentImages = <TError = unknown,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof fetchAllContentImages>>, TError,{mangaContentProviderId: number}, TContext>, request?: SecondParameter<typeof customInstance>}
, queryClient?: QueryClient): UseMutationResult<
Awaited<ReturnType<typeof fetchAllContentImages>>,
TError,
{mangaContentProviderId: number},
TContext
> => {
const mutationOptions = getFetchAllContentImagesMutationOptions(options);
return useMutation(mutationOptions, queryClient);
}
/**
* Retrieve a list of content providers
* @summary Get a list of content providers
*/

View File

@ -1,91 +0,0 @@
/**
* Generated by orval v7.17.0 🍺
* Do not edit manually.
* OpenAPI definition
* OpenAPI spec version: v0
*/
import {
useMutation
} from '@tanstack/react-query';
import type {
MutationFunction,
QueryClient,
UseMutationOptions,
UseMutationResult
} from '@tanstack/react-query';
import type {
DefaultResponseDTOVoid
} from '../api.schemas';
import { customInstance } from '../../api';
type SecondParameter<T extends (...args: never) => unknown> = Parameters<T>[1];
/**
* Fetch all not yet downloaded chapters from the provider
* @summary Fetch all chapters
*/
export const fetchAllChapters = (
mangaProviderId: number,
options?: SecondParameter<typeof customInstance>,signal?: AbortSignal
) => {
return customInstance<DefaultResponseDTOVoid>(
{url: `/mangas/${encodeURIComponent(String(mangaProviderId))}/fetch-all-chapters`, method: 'POST', signal
},
options);
}
export const getFetchAllChaptersMutationOptions = <TError = unknown,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof fetchAllChapters>>, TError,{mangaProviderId: number}, TContext>, request?: SecondParameter<typeof customInstance>}
): UseMutationOptions<Awaited<ReturnType<typeof fetchAllChapters>>, TError,{mangaProviderId: number}, TContext> => {
const mutationKey = ['fetchAllChapters'];
const {mutation: mutationOptions, request: requestOptions} = options ?
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
options
: {...options, mutation: {...options.mutation, mutationKey}}
: {mutation: { mutationKey, }, request: undefined};
const mutationFn: MutationFunction<Awaited<ReturnType<typeof fetchAllChapters>>, {mangaProviderId: number}> = (props) => {
const {mangaProviderId} = props ?? {};
return fetchAllChapters(mangaProviderId,requestOptions)
}
return { mutationFn, ...mutationOptions }}
export type FetchAllChaptersMutationResult = NonNullable<Awaited<ReturnType<typeof fetchAllChapters>>>
export type FetchAllChaptersMutationError = unknown
/**
* @summary Fetch all chapters
*/
export const useFetchAllChapters = <TError = unknown,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof fetchAllChapters>>, TError,{mangaProviderId: number}, TContext>, request?: SecondParameter<typeof customInstance>}
, queryClient?: QueryClient): UseMutationResult<
Awaited<ReturnType<typeof fetchAllChapters>>,
TError,
{mangaProviderId: number},
TContext
> => {
const mutationOptions = getFetchAllChaptersMutationOptions(options);
return useMutation(mutationOptions, queryClient);
}

View File

@ -14,7 +14,7 @@ import { useCallback } from "react";
import { useNavigate, useParams } from "react-router";
import { toast } from "sonner";
import { useGetManga } from "@/api/generated/catalog/catalog.ts";
import { useFetchContentProviderContentList } from "@/api/generated/ingestion/ingestion.ts";
import {useFetchAllContentImages, useFetchContentProviderContentList} from "@/api/generated/ingestion/ingestion.ts";
import {
useFollowManga,
useSetFavorite,
@ -53,12 +53,12 @@ const Manga = () => {
},
});
// const { mutate: fetchAllMutate, isPending: fetchAllPending } =
// useFetchAllChapters({
// mutation: {
// onSuccess: () => toast.success("Chapter import queued successfully."),
// },
// });
const { mutate: fetchAllMutate, isPending: fetchAllPending } =
useFetchAllContentImages({
mutation: {
onSuccess: () => toast.success("Chapter import queued successfully."),
},
});
const isPending = fetchPending;
@ -368,24 +368,24 @@ const Manga = () => {
</div>
{provider.supportsChapterFetch && provider.active && (
<div className={"flex gap-4 pr-4"}>
{/*<Button*/}
{/* size="sm"*/}
{/* variant="outline"*/}
{/* disabled={isPending}*/}
{/* onClick={() =>*/}
{/* fetchAllMutate({*/}
{/* mangaProviderId: provider.id?? -1,*/}
{/* })*/}
{/* }*/}
{/* className="gap-2"*/}
{/*>*/}
{/* <Database className="h-4 w-4" />*/}
{/* Fetch all from Provider*/}
{/*</Button>*/}
<Button
size="sm"
variant="outline"
disabled={isPending}
disabled={(isPending || fetchAllPending) && provider.chaptersAvailable > 0}
onClick={() =>
fetchAllMutate({
mangaContentProviderId: provider.id?? -1,
})
}
className="gap-2"
>
<Database className="h-4 w-4" />
Fetch all from Provider
</Button>
<Button
size="sm"
variant="outline"
disabled={isPending || fetchAllPending}
onClick={() =>
mutate({
mangaContentProviderId: provider.id ?? -1,
@ -394,7 +394,7 @@ const Manga = () => {
className="gap-2"
>
<Database className="h-4 w-4" />
Fetch from Provider
Fetch list from Provider
</Button>
</div>
)}