Feature/add option to remove manga from categories when removing from library (#633)
* Optionally remove manga categories when removing them from library * Use "Mangas::removeFromLibrary" * Handle uncatched promises
This commit is contained in:
@@ -18,6 +18,7 @@ import {
|
||||
} from '@/lib/graphql/generated/graphql.ts';
|
||||
import { Chapters } from '@/lib/data/Chapters.ts';
|
||||
import { makeToast } from '@/components/util/Toast.tsx';
|
||||
import { getMetadataServerSettings } from '@/util/metadataServerSettings.ts';
|
||||
|
||||
export type MangaAction =
|
||||
| 'download'
|
||||
@@ -208,10 +209,15 @@ export class Mangas {
|
||||
}
|
||||
|
||||
static async removeFromLibrary(mangaIds: number[]): Promise<void> {
|
||||
const { removeMangaFromCategories } = await getMetadataServerSettings();
|
||||
return Mangas.executeAction(
|
||||
'remove_from_library',
|
||||
mangaIds.length,
|
||||
() => requestManager.updateMangas(mangaIds, { inLibrary: false }).response,
|
||||
() =>
|
||||
requestManager.updateMangas(mangaIds, {
|
||||
updateMangas: { inLibrary: false },
|
||||
updateMangasCategories: removeMangaFromCategories ? { clearCategories: true } : undefined,
|
||||
}).response,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -2842,10 +2842,12 @@ export type UpdateMangaMutation = { __typename?: 'Mutation', updateManga: { __ty
|
||||
|
||||
export type UpdateMangasMutationVariables = Exact<{
|
||||
input: UpdateMangasInput;
|
||||
updateCategoryInput: UpdateMangasCategoriesInput;
|
||||
updateCategories: Scalars['Boolean']['input'];
|
||||
}>;
|
||||
|
||||
|
||||
export type UpdateMangasMutation = { __typename?: 'Mutation', updateMangas: { __typename?: 'UpdateMangasPayload', clientMutationId?: string | null, mangas: Array<{ __typename?: 'MangaType', id: number, inLibrary: boolean, inLibraryAt: any, categories: { __typename?: 'CategoryNodeList', totalCount: number, nodes: Array<{ __typename?: 'CategoryType', id: number, mangas: { __typename?: 'MangaNodeList', totalCount: number } }> } }> } };
|
||||
export type UpdateMangasMutation = { __typename?: 'Mutation', updateMangas: { __typename?: 'UpdateMangasPayload', clientMutationId?: string | null, mangas: Array<{ __typename?: 'MangaType', id: number, inLibrary: boolean, inLibraryAt: any, categories: { __typename?: 'CategoryNodeList', totalCount: number, nodes: Array<{ __typename?: 'CategoryType', id: number, mangas: { __typename?: 'MangaNodeList', totalCount: number } }> } }> }, updateMangasCategories?: { __typename?: 'UpdateMangasCategoriesPayload', mangas: Array<{ __typename?: 'MangaType', id: number, categories: { __typename?: 'CategoryNodeList', totalCount: number, nodes: Array<{ __typename?: 'CategoryType', id: number, mangas: { __typename?: 'MangaNodeList', totalCount: number } }> } }> } };
|
||||
|
||||
export type UpdateMangaCategoriesMutationVariables = Exact<{
|
||||
input: UpdateMangaCategoriesInput;
|
||||
|
||||
@@ -130,7 +130,11 @@ export const UPDATE_MANGA = gql`
|
||||
`;
|
||||
|
||||
export const UPDATE_MANGAS = gql`
|
||||
mutation UPDATE_MANGAS($input: UpdateMangasInput!) {
|
||||
mutation UPDATE_MANGAS(
|
||||
$input: UpdateMangasInput!
|
||||
$updateCategoryInput: UpdateMangasCategoriesInput!
|
||||
$updateCategories: Boolean!
|
||||
) {
|
||||
updateMangas(input: $input) {
|
||||
clientMutationId
|
||||
mangas {
|
||||
@@ -148,6 +152,20 @@ export const UPDATE_MANGAS = gql`
|
||||
}
|
||||
}
|
||||
}
|
||||
updateMangasCategories(input: $updateCategoryInput) @include(if: $updateCategories) {
|
||||
mangas {
|
||||
id
|
||||
categories {
|
||||
nodes {
|
||||
id
|
||||
mangas {
|
||||
totalCount
|
||||
}
|
||||
}
|
||||
totalCount
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
|
||||
@@ -1584,13 +1584,17 @@ export class RequestManager {
|
||||
|
||||
public updateMangas(
|
||||
ids: number[],
|
||||
patch: UpdateMangaPatchInput,
|
||||
patch: { updateMangas: UpdateMangaPatchInput; updateMangasCategories?: UpdateMangaCategoriesPatchInput },
|
||||
options?: MutationOptions<UpdateMangasMutation, UpdateMangasMutationVariables>,
|
||||
): AbortableApolloMutationResponse<UpdateMangasMutation> {
|
||||
const result = this.doRequest<UpdateMangasMutation, UpdateMangasMutationVariables>(
|
||||
GQLMethod.MUTATION,
|
||||
UPDATE_MANGAS,
|
||||
{ input: { ids, patch } },
|
||||
{
|
||||
input: { ids, patch: patch.updateMangas },
|
||||
updateCategoryInput: { ids, patch: patch.updateMangasCategories ?? {} },
|
||||
updateCategories: !!patch.updateMangasCategories,
|
||||
},
|
||||
options,
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user