From e1f338d0132e2970d9e4467b94a133fae2aebf72 Mon Sep 17 00:00:00 2001 From: schroda <50052685+schroda@users.noreply.github.com> Date: Fri, 1 Sep 2023 20:29:19 +0200 Subject: [PATCH] Use gql for "sources" --- src/lib/requests/RequestManager.ts | 19 ++++++++++++++----- src/screens/SearchAll.tsx | 3 ++- src/screens/SourceMangas.tsx | 3 ++- src/screens/Sources.tsx | 3 ++- 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/lib/requests/RequestManager.ts b/src/lib/requests/RequestManager.ts index 84df632c..203d9f61 100644 --- a/src/lib/requests/RequestManager.ts +++ b/src/lib/requests/RequestManager.ts @@ -29,7 +29,6 @@ import { IManga, IMangaChapter, IncludeInGlobalUpdate, - ISource, ISourceFilters, IUpdateStatus, PaginatedList, @@ -51,6 +50,10 @@ import { GetExtensionsQueryVariables, GetGlobalMetadatasQuery, GetGlobalMetadatasQueryVariables, + GetSourceQuery, + GetSourceQueryVariables, + GetSourcesQuery, + GetSourcesQueryVariables, InstallExternalExtensionMutation, InstallExternalExtensionMutationVariables, SetGlobalMetadataMutation, @@ -68,6 +71,7 @@ import { INSTALL_EXTERNAL_EXTENSION, UPDATE_EXTENSION, } from '@/lib/graphql/mutations/ExtensionMutation.ts'; +import { GET_SOURCE, GET_SOURCES } from '@/lib/graphql/queries/SourceQuery.ts'; enum SWRHttpMethod { SWR_GET, @@ -513,12 +517,17 @@ export class RequestManager { return this.getValidImgUrlFor(`extension/icon/${extension}`); } - public useGetSourceList(swrOptions?: SWROptions): AbortableSWRResponse { - return this.doRequest(HttpMethod.SWR_GET, 'source/list', { swrOptions }); + public useGetSourceList( + options?: QueryHookOptions, + ): AbortableApolloUseQueryResponse { + return this.doRequestNew(GQLMethod.USE_QUERY, GET_SOURCES, {}, options); } - public useGetSource(sourceId: string, swrOptions?: SWROptions): AbortableSWRResponse { - return this.doRequest(HttpMethod.SWR_GET, `source/${sourceId}`, { swrOptions }); + public useGetSource( + id: string, + options?: QueryHookOptions, + ): AbortableApolloUseQueryResponse { + return this.doRequestNew(GQLMethod.USE_QUERY, GET_SOURCE, { id }, options); } public useGetSourcePopularMangas( diff --git a/src/screens/SearchAll.tsx b/src/screens/SearchAll.tsx index 78f27d3a..1a337a30 100644 --- a/src/screens/SearchAll.tsx +++ b/src/screens/SearchAll.tsx @@ -169,7 +169,8 @@ const SearchAll: React.FC = () => { const [shownLangs, setShownLangs] = useLocalStorage('shownSourceLangs', sourceDefualtLangs()); const [showNsfw] = useLocalStorage('showNsfw', true); - const { data: sources = [] } = requestManager.useGetSourceList(); + const { data } = requestManager.useGetSourceList(); + const sources = data?.sources.nodes ?? []; const [sourceToLoadingStateMap, setSourceToLoadingStateMap] = useState(new Map()); const debouncedSourceToLoadingStateMap = useDebounce(sourceToLoadingStateMap, 500); diff --git a/src/screens/SourceMangas.tsx b/src/screens/SourceMangas.tsx index 187a0df1..038360b8 100644 --- a/src/screens/SourceMangas.tsx +++ b/src/screens/SourceMangas.tsx @@ -188,7 +188,8 @@ export default function SourceMangas() { abortRequest, } = useSourceManga(sourceId, contentType, searchTerm, filtersToApply, isLargeScreen ? 2 : 1); const { data: filters = [], mutate: mutateFilters } = requestManager.useGetSourceFilters(sourceId); - const { data: source } = requestManager.useGetSource(sourceId); + const { data } = requestManager.useGetSource(sourceId); + const source = data?.source; const [triggerDataRefresh, setTriggerDataRefresh] = useState(false); const message = !isLoading ? t(SOURCE_CONTENT_TYPE_TO_ERROR_MSG_KEY[contentType]) : undefined; diff --git a/src/screens/Sources.tsx b/src/screens/Sources.tsx index 1143a10a..c4412c9c 100644 --- a/src/screens/Sources.tsx +++ b/src/screens/Sources.tsx @@ -53,7 +53,8 @@ export default function Sources() { const [shownLangs, setShownLangs] = useLocalStorage('shownSourceLangs', sourceDefualtLangs()); const [showNsfw] = useLocalStorage('showNsfw', true); - const { data: sources, isLoading } = requestManager.useGetSourceList(); + const { data, loading: isLoading } = requestManager.useGetSourceList(); + const sources = data?.sources.nodes; const navigate = useNavigate();