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