Fix refreshing manga during migration search
This commit is contained in:
@@ -13,23 +13,23 @@ import { baseCleanup } from '@/base/utils/Strings.ts';
|
|||||||
|
|
||||||
export const useRefreshManga = (mangaId: string) => {
|
export const useRefreshManga = (mangaId: string) => {
|
||||||
const [fetchingOnline, setFetchingOnline] = useState(false);
|
const [fetchingOnline, setFetchingOnline] = useState(false);
|
||||||
const [error, setError] = useState(null);
|
const [error, setError] = useState<unknown>(null);
|
||||||
|
|
||||||
const handleRefresh = useCallback(async () => {
|
const handleRefresh = useCallback(async () => {
|
||||||
setFetchingOnline(true);
|
setFetchingOnline(true);
|
||||||
setError(null);
|
setError(null);
|
||||||
await Promise.all([
|
|
||||||
requestManager.getMangaFetch(mangaId, { awaitRefetchQueries: true }).response,
|
|
||||||
requestManager.getMangaChaptersFetch(mangaId, { awaitRefetchQueries: true }).response,
|
|
||||||
])
|
|
||||||
.catch((e) => {
|
|
||||||
if (CombinedGraphQLErrors.is(e) && baseCleanup(e.message) === 'no chapters found') {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
setError(e);
|
try {
|
||||||
})
|
await requestManager.refreshManga(mangaId, { awaitRefetchQueries: true }).response;
|
||||||
.finally(() => setFetchingOnline(false));
|
} catch (e) {
|
||||||
|
if (CombinedGraphQLErrors.is(e) && baseCleanup(e.message) === 'no chapters found') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setError(e);
|
||||||
|
} finally {
|
||||||
|
setFetchingOnline(false);
|
||||||
|
}
|
||||||
}, [mangaId]);
|
}, [mangaId]);
|
||||||
|
|
||||||
return [handleRefresh, { loading: fetchingOnline, error }] as const;
|
return [handleRefresh, { loading: fetchingOnline, error }] as const;
|
||||||
|
|||||||
@@ -698,9 +698,18 @@ export class MigrationManager {
|
|||||||
throw new Error(signal.reason);
|
throw new Error(signal.reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
const updatedMatch = await requestManager.getMangaFetch(match.id).response;
|
return (async () => {
|
||||||
|
try {
|
||||||
|
const updatedMatch = await requestManager.refreshManga(match.id, { awaitRefetchQueries: true })
|
||||||
|
.response;
|
||||||
|
|
||||||
return updatedMatch.data?.fetchManga?.manga ?? match;
|
return updatedMatch.data?.fetchManga?.manga ?? match;
|
||||||
|
} catch (e) {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
|
||||||
|
return match;
|
||||||
|
})();
|
||||||
});
|
});
|
||||||
|
|
||||||
const updatedMatches = await Promise.all(matchUpdatePromises);
|
const updatedMatches = await Promise.all(matchUpdatePromises);
|
||||||
|
|||||||
@@ -3933,6 +3933,13 @@ export type GetMangaFetchMutationVariables = Exact<{
|
|||||||
|
|
||||||
export type GetMangaFetchMutation = { __typename?: 'Mutation', fetchManga?: { __typename?: 'FetchMangaPayload', manga: { __typename?: 'MangaType', artist?: string | null, author?: string | null, description?: string | null, status: MangaStatus, realUrl?: string | null, sourceId: string, genre: Array<string>, lastFetchedAt?: string | null, inLibraryAt: string, id: number, title: string, thumbnailUrl?: string | null, thumbnailUrlLastFetched?: string | null, inLibrary: boolean, initialized: boolean, unreadCount: number, downloadCount: number, bookmarkCount: number, hasDuplicateChapters: boolean, meta: Array<{ __typename?: 'MangaMetaType', mangaId: number, key: string, value: string }>, source?: { __typename?: 'SourceType', id: string, name: string, displayName: string, lang: string, iconUrl: string } | null, trackRecords: { __typename?: 'TrackRecordNodeList', totalCount: number, nodes: Array<{ __typename?: 'TrackRecordType', id: number, trackerId: number }> }, firstUnreadChapter?: { __typename?: 'ChapterType', id: number, sourceOrder: number, isRead: boolean, mangaId: number, chapterNumber: number, name: string, scanlator?: string | null } | null, lastReadChapter?: { __typename?: 'ChapterType', id: number, sourceOrder: number, lastReadAt: string } | null, latestReadChapter?: { __typename?: 'ChapterType', id: number, sourceOrder: number, lastReadAt: string } | null, latestFetchedChapter?: { __typename?: 'ChapterType', id: number, fetchedAt: string } | null, latestUploadedChapter?: { __typename?: 'ChapterType', id: number, uploadDate: string } | null, highestNumberedChapter?: { __typename?: 'ChapterType', id: number, chapterNumber: number } | null, chapters: { __typename?: 'ChapterNodeList', totalCount: number } } } | null };
|
export type GetMangaFetchMutation = { __typename?: 'Mutation', fetchManga?: { __typename?: 'FetchMangaPayload', manga: { __typename?: 'MangaType', artist?: string | null, author?: string | null, description?: string | null, status: MangaStatus, realUrl?: string | null, sourceId: string, genre: Array<string>, lastFetchedAt?: string | null, inLibraryAt: string, id: number, title: string, thumbnailUrl?: string | null, thumbnailUrlLastFetched?: string | null, inLibrary: boolean, initialized: boolean, unreadCount: number, downloadCount: number, bookmarkCount: number, hasDuplicateChapters: boolean, meta: Array<{ __typename?: 'MangaMetaType', mangaId: number, key: string, value: string }>, source?: { __typename?: 'SourceType', id: string, name: string, displayName: string, lang: string, iconUrl: string } | null, trackRecords: { __typename?: 'TrackRecordNodeList', totalCount: number, nodes: Array<{ __typename?: 'TrackRecordType', id: number, trackerId: number }> }, firstUnreadChapter?: { __typename?: 'ChapterType', id: number, sourceOrder: number, isRead: boolean, mangaId: number, chapterNumber: number, name: string, scanlator?: string | null } | null, lastReadChapter?: { __typename?: 'ChapterType', id: number, sourceOrder: number, lastReadAt: string } | null, latestReadChapter?: { __typename?: 'ChapterType', id: number, sourceOrder: number, lastReadAt: string } | null, latestFetchedChapter?: { __typename?: 'ChapterType', id: number, fetchedAt: string } | null, latestUploadedChapter?: { __typename?: 'ChapterType', id: number, uploadDate: string } | null, highestNumberedChapter?: { __typename?: 'ChapterType', id: number, chapterNumber: number } | null, chapters: { __typename?: 'ChapterNodeList', totalCount: number } } } | null };
|
||||||
|
|
||||||
|
export type RefreshMangaMutationVariables = Exact<{
|
||||||
|
id: Scalars['Int']['input'];
|
||||||
|
}>;
|
||||||
|
|
||||||
|
|
||||||
|
export type RefreshMangaMutation = { __typename?: 'Mutation', fetchChapters?: { __typename?: 'FetchChaptersPayload', chapters: Array<{ __typename?: 'ChapterType', fetchedAt: string, uploadDate: string, lastReadAt: string, id: number, name: string, mangaId: number, scanlator?: string | null, realUrl?: string | null, sourceOrder: number, chapterNumber: number, isRead: boolean, isDownloaded: boolean, isBookmarked: boolean }> } | null, fetchManga?: { __typename?: 'FetchMangaPayload', manga: { __typename?: 'MangaType', artist?: string | null, author?: string | null, description?: string | null, status: MangaStatus, realUrl?: string | null, sourceId: string, genre: Array<string>, lastFetchedAt?: string | null, inLibraryAt: string, id: number, title: string, thumbnailUrl?: string | null, thumbnailUrlLastFetched?: string | null, inLibrary: boolean, initialized: boolean, unreadCount: number, downloadCount: number, bookmarkCount: number, hasDuplicateChapters: boolean, meta: Array<{ __typename?: 'MangaMetaType', mangaId: number, key: string, value: string }>, source?: { __typename?: 'SourceType', id: string, name: string, displayName: string, lang: string, iconUrl: string } | null, trackRecords: { __typename?: 'TrackRecordNodeList', totalCount: number, nodes: Array<{ __typename?: 'TrackRecordType', id: number, trackerId: number }> }, firstUnreadChapter?: { __typename?: 'ChapterType', id: number, sourceOrder: number, isRead: boolean, mangaId: number, chapterNumber: number, name: string, scanlator?: string | null } | null, lastReadChapter?: { __typename?: 'ChapterType', id: number, sourceOrder: number, lastReadAt: string } | null, latestReadChapter?: { __typename?: 'ChapterType', id: number, sourceOrder: number, lastReadAt: string } | null, latestFetchedChapter?: { __typename?: 'ChapterType', id: number, fetchedAt: string } | null, latestUploadedChapter?: { __typename?: 'ChapterType', id: number, uploadDate: string } | null, highestNumberedChapter?: { __typename?: 'ChapterType', id: number, chapterNumber: number } | null, chapters: { __typename?: 'ChapterNodeList', totalCount: number } } } | null };
|
||||||
|
|
||||||
export type GetMangaToMigrateToFetchMutationVariables = Exact<{
|
export type GetMangaToMigrateToFetchMutationVariables = Exact<{
|
||||||
id: Scalars['Int']['input'];
|
id: Scalars['Int']['input'];
|
||||||
migrateChapters: Scalars['Boolean']['input'];
|
migrateChapters: Scalars['Boolean']['input'];
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
import gql from 'graphql-tag';
|
import gql from 'graphql-tag';
|
||||||
import { MANGA_META_FIELDS, MANGA_SCREEN_FIELDS } from '@/lib/graphql/manga/MangaFragments.ts';
|
import { MANGA_META_FIELDS, MANGA_SCREEN_FIELDS } from '@/lib/graphql/manga/MangaFragments.ts';
|
||||||
|
import { CHAPTER_LIST_FIELDS } from '@/lib/graphql/chapter/ChapterFragments.ts';
|
||||||
|
|
||||||
// makes the server fetch and return the manga
|
// makes the server fetch and return the manga
|
||||||
export const GET_MANGA_FETCH = gql`
|
export const GET_MANGA_FETCH = gql`
|
||||||
@@ -22,6 +23,25 @@ export const GET_MANGA_FETCH = gql`
|
|||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
// makes the server fetch and return the manga
|
||||||
|
export const REFRESH_MANGA = gql`
|
||||||
|
${MANGA_SCREEN_FIELDS}
|
||||||
|
${CHAPTER_LIST_FIELDS}
|
||||||
|
|
||||||
|
mutation REFRESH_MANGA($id: Int!) {
|
||||||
|
fetchChapters(input: { mangaId: $id }) {
|
||||||
|
chapters {
|
||||||
|
...CHAPTER_LIST_FIELDS
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fetchManga(input: { id: $id }) {
|
||||||
|
manga {
|
||||||
|
...MANGA_SCREEN_FIELDS
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
// makes the server fetch and return the manga
|
// makes the server fetch and return the manga
|
||||||
export const GET_MANGA_TO_MIGRATE_TO_FETCH = gql`
|
export const GET_MANGA_TO_MIGRATE_TO_FETCH = gql`
|
||||||
mutation GET_MANGA_TO_MIGRATE_TO_FETCH(
|
mutation GET_MANGA_TO_MIGRATE_TO_FETCH(
|
||||||
|
|||||||
@@ -212,6 +212,8 @@ import type {
|
|||||||
DeleteChapterMetasInput,
|
DeleteChapterMetasInput,
|
||||||
SetCategoryMetasInput,
|
SetCategoryMetasInput,
|
||||||
DeleteCategoryMetasInput,
|
DeleteCategoryMetasInput,
|
||||||
|
RefreshMangaMutation,
|
||||||
|
RefreshMangaMutationVariables,
|
||||||
} from '@/lib/graphql/generated/graphql.ts';
|
} from '@/lib/graphql/generated/graphql.ts';
|
||||||
import {
|
import {
|
||||||
CategoryOrderBy,
|
CategoryOrderBy,
|
||||||
@@ -240,6 +242,7 @@ import { GET_MIGRATABLE_SOURCES, GET_SOURCES_LIST } from '@/lib/graphql/source/S
|
|||||||
import {
|
import {
|
||||||
GET_MANGA_FETCH,
|
GET_MANGA_FETCH,
|
||||||
GET_MANGA_TO_MIGRATE_TO_FETCH,
|
GET_MANGA_TO_MIGRATE_TO_FETCH,
|
||||||
|
REFRESH_MANGA,
|
||||||
UPDATE_MANGA,
|
UPDATE_MANGA,
|
||||||
UPDATE_MANGA_CATEGORIES,
|
UPDATE_MANGA_CATEGORIES,
|
||||||
UPDATE_MANGA_METADATA,
|
UPDATE_MANGA_METADATA,
|
||||||
@@ -2218,6 +2221,20 @@ export class RequestManager {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public refreshManga(
|
||||||
|
mangaId: number | string,
|
||||||
|
options?: MutationOptions<RefreshMangaMutation, RefreshMangaMutationVariables>,
|
||||||
|
): AbortableApolloMutationResponse<RefreshMangaMutation> {
|
||||||
|
return this.doRequest<RefreshMangaMutation, RefreshMangaMutationVariables>(
|
||||||
|
GQLMethod.MUTATION,
|
||||||
|
REFRESH_MANGA,
|
||||||
|
{
|
||||||
|
id: Number(mangaId),
|
||||||
|
},
|
||||||
|
{ refetchQueries: [GET_CHAPTERS_MANGA], ...options },
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
public getMangaToMigrateToFetch(
|
public getMangaToMigrateToFetch(
|
||||||
mangaId: number | string,
|
mangaId: number | string,
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user