Use gql for "global metadata"
This commit is contained in:
@@ -34,7 +34,6 @@ import {
|
||||
ISource,
|
||||
ISourceFilters,
|
||||
IUpdateStatus,
|
||||
Metadata,
|
||||
PaginatedList,
|
||||
PaginatedMangaList,
|
||||
SourcePreferences,
|
||||
@@ -44,6 +43,14 @@ import {
|
||||
import { HttpMethod as DefaultHttpMethod, IRestClient, RestClient } from '@/lib/requests/client/RestClient.ts';
|
||||
import storage from '@/util/localStorage.tsx';
|
||||
import { GraphQLClient } from '@/lib/requests/client/GraphQLClient.ts';
|
||||
import {
|
||||
GetGlobalMetadatasQuery,
|
||||
GetGlobalMetadatasQueryVariables,
|
||||
SetGlobalMetadataMutation,
|
||||
SetGlobalMetadataMutationVariables,
|
||||
} from '@/lib/graphql/generated/graphql.ts';
|
||||
import { GET_GLOBAL_METADATA, GET_GLOBAL_METADATAS } from '@/lib/graphql/queries/GlobalMetadataQuery.ts';
|
||||
import { SET_GLOBAL_METADATA } from '@/lib/graphql/mutations/GlobalMetadataMutation.ts';
|
||||
|
||||
enum SWRHttpMethod {
|
||||
SWR_GET,
|
||||
@@ -423,12 +430,19 @@ export class RequestManager {
|
||||
}
|
||||
}
|
||||
|
||||
public useGetGlobalMeta(swrOptions?: SWROptions<Metadata>): AbortableSWRResponse<Metadata> {
|
||||
return this.doRequest(HttpMethod.SWR_GET, 'meta', { swrOptions });
|
||||
public useGetGlobalMeta(
|
||||
options?: QueryHookOptions<GetGlobalMetadatasQuery, GetGlobalMetadatasQueryVariables>,
|
||||
): AbortableApolloUseQueryResponse<GetGlobalMetadatasQuery, GetGlobalMetadatasQueryVariables> {
|
||||
return this.doRequestNew(GQLMethod.USE_QUERY, GET_GLOBAL_METADATAS, {}, options);
|
||||
}
|
||||
|
||||
public setGlobalMetadata(key: string, value: any): AbortableAxiosResponse {
|
||||
return this.doRequest(HttpMethod.PATCH, 'meta', { formData: { key, value } });
|
||||
public setGlobalMetadata(key: string, value: any): AbortableApolloMutationResponse<SetGlobalMetadataMutation> {
|
||||
return this.doRequestNew<SetGlobalMetadataMutation, SetGlobalMetadataMutationVariables>(
|
||||
GQLMethod.MUTATION,
|
||||
SET_GLOBAL_METADATA,
|
||||
{ input: { meta: { key, value: `${value}` } } },
|
||||
{ refetchQueries: [GET_GLOBAL_METADATA, GET_GLOBAL_METADATAS] },
|
||||
);
|
||||
}
|
||||
|
||||
public useGetAbout(swrOptions?: SWROptions<IAbout>): AbortableSWRResponse<IAbout> {
|
||||
|
||||
@@ -20,6 +20,7 @@ import {
|
||||
MetadataKeyValuePair,
|
||||
} from '@/typings';
|
||||
import requestManager, { RequestManager } from '@/lib/requests/RequestManager.ts';
|
||||
import { MetaType } from '@/lib/graphql/generated/graphql.ts';
|
||||
|
||||
const APP_METADATA_KEY_PREFIX = 'webUI_';
|
||||
|
||||
@@ -362,3 +363,16 @@ export const requestUpdateCategoryMetadata = async (
|
||||
category: ICategory,
|
||||
keysToValues: MetadataKeyValuePair[],
|
||||
): Promise<void[]> => requestUpdateMetadata(category, 'category', keysToValues);
|
||||
|
||||
export const convertGqlMetadata = (gqlMetadata?: MetaType[]): Metadata | undefined => {
|
||||
if (!gqlMetadata) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const metadata: Metadata = {};
|
||||
gqlMetadata.forEach(({ key, value }) => {
|
||||
metadata[key] = value;
|
||||
});
|
||||
|
||||
return metadata;
|
||||
};
|
||||
|
||||
@@ -8,7 +8,12 @@
|
||||
|
||||
import { IManga, Metadata, MetadataHolder, IReaderSettings, MetadataKeyValuePair } from '@/typings';
|
||||
import requestManager from '@/lib/requests/RequestManager.ts';
|
||||
import { getMetadataFrom, requestUpdateMangaMetadata, requestUpdateServerMetadata } from '@/util/metadata';
|
||||
import {
|
||||
convertGqlMetadata,
|
||||
getMetadataFrom,
|
||||
requestUpdateMangaMetadata,
|
||||
requestUpdateServerMetadata,
|
||||
} from '@/util/metadata';
|
||||
|
||||
type UndefinedReaderSettings = {
|
||||
[setting in keyof IReaderSettings]: IReaderSettings[setting] | undefined;
|
||||
@@ -47,10 +52,11 @@ export const useDefaultReaderSettings = (): {
|
||||
settings: IReaderSettings;
|
||||
loading: boolean;
|
||||
} => {
|
||||
const { data: meta, isLoading } = requestManager.useGetGlobalMeta();
|
||||
const settings = getReaderSettingsWithDefaultValueFallback<IReaderSettings>(meta);
|
||||
const { data, loading } = requestManager.useGetGlobalMeta();
|
||||
const metadata = convertGqlMetadata(data?.metas.nodes);
|
||||
const settings = getReaderSettingsWithDefaultValueFallback<IReaderSettings>(metadata);
|
||||
|
||||
return { metadata: meta, settings, loading: isLoading };
|
||||
return { metadata, settings, loading };
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
import { Metadata, ISearchSettings } from '@/typings';
|
||||
import requestManager from '@/lib/requests/RequestManager.ts';
|
||||
import { getMetadataFrom } from '@/util/metadata';
|
||||
import { convertGqlMetadata, getMetadataFrom } from '@/util/metadata';
|
||||
|
||||
export const getDefaultSettings = (): ISearchSettings => ({
|
||||
ignoreFilters: false,
|
||||
@@ -24,8 +24,9 @@ export const useSearchSettings = (): {
|
||||
settings: ISearchSettings;
|
||||
loading: boolean;
|
||||
} => {
|
||||
const { data: meta, isLoading } = requestManager.useGetGlobalMeta();
|
||||
const settings = getSearchSettingsWithDefaultValueFallback(meta);
|
||||
const { data, loading } = requestManager.useGetGlobalMeta();
|
||||
const metadata = convertGqlMetadata(data?.metas.nodes);
|
||||
const settings = getSearchSettingsWithDefaultValueFallback(metadata);
|
||||
|
||||
return { metadata: meta, settings, loading: isLoading };
|
||||
return { metadata, settings, loading };
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user